-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doc gen: Attributes to support related_udf
, alternative_syntax
#13575
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
0b73ab9
Doc gen: Rust custom attributes support `related_udf`, `alternative_s…
comphead 03c80b0
Doc gen: Rust custom attributes support `related_udf`, `alternative_s…
comphead 9943d22
Doc gen: Rust custom attributes support `related_udf`, `alternative_s…
comphead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,8 +56,12 @@ pub struct Documentation { | |
|
||
impl Documentation { | ||
/// Returns a new [`DocumentationBuilder`] with no options set. | ||
pub fn builder() -> DocumentationBuilder { | ||
DocumentationBuilder::new() | ||
pub fn builder( | ||
doc_section: DocSection, | ||
description: impl Into<String>, | ||
syntax_example: impl Into<String>, | ||
) -> DocumentationBuilder { | ||
DocumentationBuilder::new(doc_section, description, syntax_example) | ||
} | ||
} | ||
|
||
|
@@ -86,29 +90,30 @@ pub struct DocSection { | |
/// description: None, | ||
/// }; | ||
/// | ||
/// let documentation = Documentation::builder() | ||
/// .with_doc_section(doc_section) | ||
/// .with_description("Add one to an int32") | ||
/// .with_syntax_example("add_one(2)") | ||
/// let documentation = Documentation::builder(doc_section, "Add one to an int32".to_owned(), "add_one(2)".to_owned()) | ||
/// .with_argument("arg_1", "The int32 number to add one to") | ||
/// .build(); | ||
/// # } | ||
pub struct DocumentationBuilder { | ||
pub doc_section: Option<DocSection>, | ||
pub description: Option<String>, | ||
pub syntax_example: Option<String>, | ||
pub doc_section: DocSection, | ||
pub description: String, | ||
pub syntax_example: String, | ||
pub sql_example: Option<String>, | ||
pub arguments: Option<Vec<(String, String)>>, | ||
pub alternative_syntax: Option<Vec<String>>, | ||
pub related_udfs: Option<Vec<String>>, | ||
} | ||
|
||
impl DocumentationBuilder { | ||
pub fn new() -> Self { | ||
pub fn new( | ||
doc_section: DocSection, | ||
description: impl Into<String>, | ||
syntax_example: impl Into<String>, | ||
) -> Self { | ||
Self { | ||
doc_section: None, | ||
description: None, | ||
syntax_example: None, | ||
doc_section, | ||
description: description.into(), | ||
syntax_example: syntax_example.into(), | ||
sql_example: None, | ||
arguments: None, | ||
alternative_syntax: None, | ||
|
@@ -117,17 +122,17 @@ impl DocumentationBuilder { | |
} | ||
|
||
pub fn with_doc_section(mut self, doc_section: DocSection) -> Self { | ||
self.doc_section = Some(doc_section); | ||
self.doc_section = doc_section; | ||
self | ||
} | ||
|
||
pub fn with_description(mut self, description: impl Into<String>) -> Self { | ||
self.description = Some(description.into()); | ||
self.description = description.into(); | ||
self | ||
} | ||
|
||
pub fn with_syntax_example(mut self, syntax_example: impl Into<String>) -> Self { | ||
self.syntax_example = Some(syntax_example.into()); | ||
self.syntax_example = syntax_example.into(); | ||
self | ||
} | ||
|
||
|
@@ -205,30 +210,14 @@ impl DocumentationBuilder { | |
related_udfs, | ||
} = self; | ||
|
||
if doc_section.is_none() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
panic!("Documentation must have a doc section"); | ||
} | ||
if description.is_none() { | ||
panic!("Documentation must have a description"); | ||
} | ||
if syntax_example.is_none() { | ||
panic!("Documentation must have a syntax_example"); | ||
} | ||
|
||
Documentation { | ||
doc_section: doc_section.unwrap(), | ||
description: description.unwrap(), | ||
syntax_example: syntax_example.unwrap(), | ||
doc_section, | ||
description, | ||
syntax_example, | ||
sql_example, | ||
arguments, | ||
alternative_syntax, | ||
related_udfs, | ||
} | ||
} | ||
} | ||
|
||
impl Default for DocumentationBuilder { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for anyone following along these settings are required, otherwise the builder will error (or now panic)
So I think the idea here is that the compiler can now verify the required fields which seems like an improvement to me, even though it is an API change
cc @Omega359
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gain one thing, loose another. Those fields now no longer have obvious names as they did previously if you are looking at them outside of an IDE. It's ok but it's obviously not the choice I made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats' correct. But another thing to mention the builder API mostly gonna be used internally within documentation generator crate so the user has to deal with attributes rather than API itself.
The following PR I'm intending to replace API approach to attributes where it is possible to, probably going crate by crate.
Thanks @alamb and @Omega359
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for mentioning that as I had forgotten that.