@@ -56,8 +56,12 @@ pub struct Documentation {
5656
5757impl Documentation {
5858 /// Returns a new [`DocumentationBuilder`] with no options set.
59- pub fn builder ( ) -> DocumentationBuilder {
60- DocumentationBuilder :: new ( )
59+ pub fn builder (
60+ doc_section : DocSection ,
61+ description : impl Into < String > ,
62+ syntax_example : impl Into < String > ,
63+ ) -> DocumentationBuilder {
64+ DocumentationBuilder :: new ( doc_section, description, syntax_example)
6165 }
6266}
6367
@@ -86,29 +90,30 @@ pub struct DocSection {
8690/// description: None,
8791/// };
8892///
89- /// let documentation = Documentation::builder()
90- /// .with_doc_section(doc_section)
91- /// .with_description("Add one to an int32")
92- /// .with_syntax_example("add_one(2)")
93+ /// let documentation = Documentation::builder(doc_section, "Add one to an int32".to_owned(), "add_one(2)".to_owned())
9394/// .with_argument("arg_1", "The int32 number to add one to")
9495/// .build();
9596/// # }
9697pub struct DocumentationBuilder {
97- pub doc_section : Option < DocSection > ,
98- pub description : Option < String > ,
99- pub syntax_example : Option < String > ,
98+ pub doc_section : DocSection ,
99+ pub description : String ,
100+ pub syntax_example : String ,
100101 pub sql_example : Option < String > ,
101102 pub arguments : Option < Vec < ( String , String ) > > ,
102103 pub alternative_syntax : Option < Vec < String > > ,
103104 pub related_udfs : Option < Vec < String > > ,
104105}
105106
106107impl DocumentationBuilder {
107- pub fn new ( ) -> Self {
108+ pub fn new (
109+ doc_section : DocSection ,
110+ description : impl Into < String > ,
111+ syntax_example : impl Into < String > ,
112+ ) -> Self {
108113 Self {
109- doc_section : None ,
110- description : None ,
111- syntax_example : None ,
114+ doc_section,
115+ description : description . into ( ) ,
116+ syntax_example : syntax_example . into ( ) ,
112117 sql_example : None ,
113118 arguments : None ,
114119 alternative_syntax : None ,
@@ -117,17 +122,17 @@ impl DocumentationBuilder {
117122 }
118123
119124 pub fn with_doc_section ( mut self , doc_section : DocSection ) -> Self {
120- self . doc_section = Some ( doc_section) ;
125+ self . doc_section = doc_section;
121126 self
122127 }
123128
124129 pub fn with_description ( mut self , description : impl Into < String > ) -> Self {
125- self . description = Some ( description. into ( ) ) ;
130+ self . description = description. into ( ) ;
126131 self
127132 }
128133
129134 pub fn with_syntax_example ( mut self , syntax_example : impl Into < String > ) -> Self {
130- self . syntax_example = Some ( syntax_example. into ( ) ) ;
135+ self . syntax_example = syntax_example. into ( ) ;
131136 self
132137 }
133138
@@ -205,30 +210,14 @@ impl DocumentationBuilder {
205210 related_udfs,
206211 } = self ;
207212
208- if doc_section. is_none ( ) {
209- panic ! ( "Documentation must have a doc section" ) ;
210- }
211- if description. is_none ( ) {
212- panic ! ( "Documentation must have a description" ) ;
213- }
214- if syntax_example. is_none ( ) {
215- panic ! ( "Documentation must have a syntax_example" ) ;
216- }
217-
218213 Documentation {
219- doc_section : doc_section . unwrap ( ) ,
220- description : description . unwrap ( ) ,
221- syntax_example : syntax_example . unwrap ( ) ,
214+ doc_section,
215+ description,
216+ syntax_example,
222217 sql_example,
223218 arguments,
224219 alternative_syntax,
225220 related_udfs,
226221 }
227222 }
228223}
229-
230- impl Default for DocumentationBuilder {
231- fn default ( ) -> Self {
232- Self :: new ( )
233- }
234- }
0 commit comments