Repository navigation
feat!: Use bon builder style instead of several methods - #472
Conversation
Instead of having several methods like: Schema::array(Schema) and Schema::array_with_attributes(Schema, BTreeMap) we could use Bon's function builders with start_fn: ``` Schema::array(Schema).call() Schema::array(Schema).attributes(BTreeMap).call() ``` The only annoying part is the `.call()`
|
@Kriskras99 What do you think about this ? |
|
I think this would definitely be an improvement, but maybe better as a builder directly on This is also very useful for other functions which take schemata indeed |
According to https://bon-rs.com/guide/overview#method-builder only
But I think I can overwrite the finish_fn and rename |
|
https://bon-rs.com/reference/builder/top-level/finish_fn should let you change the name |
Kriskras99
left a comment
There was a problem hiding this comment.
We should all documentation to the function arguments so that the generated builder gets documentation: https://bon-rs.com/guide/basics/documenting
| #[builder(finish_fn = build)] | ||
| pub fn builder( | ||
| #[builder(start_fn)] reader: R, | ||
| schema: Option<&'a Schema>, |
There was a problem hiding this comment.
Maybe rename this to reader_schema, so it's clearer that this is not the writer schema
Simplify the resolution of `schemata`
|
Ideas what else could use this style ? |
…ema::map() Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
|
The We can do that in a separate PR. |
It does not use Bon builders as the other methods because it has just a single argument (Vec<String>) and we don't expect that more will be ever added.
582b5d6 to
5328dfe
Compare
* feat!: Use bon builder style instead of several methods Instead of having several methods like: Schema::array(Schema) and Schema::array_with_attributes(Schema, BTreeMap) we could use Bon's function builders with start_fn: ``` Schema::array(Schema).call() Schema::array(Schema).attributes(BTreeMap).call() ``` The only annoying part is the `.call()` * Fix doc tests. * Use `.build()` as a finish_fn for the bon style function builders * Use bon function builder for Schema::map() too * Use Bon function style builder for Reader constructors * Re-add the docstring for the convenience Reader::new() ctor Simplify the resolution of `schemata` * Rename Reader's schema to reader_schema for more clarity * Add arguments for the new `default` fields in Schema::array() and Schema::map() Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * Add a Schema::r#enum() builder method Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * Add Schema::fixed(name, size) builder method Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * Add Schema::record() builder Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * Extract the builder methods and their tests into a module. Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * Fix the issue number in the unit tests' names * Move Schema::union() to schema/builders.rs It does not use Bon builders as the other methods because it has just a single argument (Vec<String>) and we don't expect that more will be ever added. --------- Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Instead of having several methods like:
Schema::array(Schema)andSchema::array_with_attributes(Schema, BTreeMap)we could use Bon's function builders with start_fn:The only annoying part is the
.call()