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
Add derive macro for Collection #138
Comments
I could look into this as I said, but while I do know derive Macros, I have not a lot of experience with bonsaidb :) |
I would love for you to try your hand at it if you're feeling motivated. My pre-coffee brain didn't see the offer for help. I think I might prefer this syntax, but play around with some variations and see what you think feels most natural: #[derive(Collection)]
#[collection(name = "Name", authority = "Authority", views = [a,b,c])]
struct MyCollection {...} There's a crate bonsaidb-macros for these proc-macros to live within already. It could probably use some cleanup, as I believe it was my first set of proc macros ever. If that syntax for views breaks rust-analyzer or you have a different idea on how to tackle that, feel free to suggest alternate ideas! |
I also added trybuild to test the error messages of derive macro. The macro does not check for name validity as the restrictions will be removed khonsulabs#143 (comment). closes khonsulabs#138 partially
As per Discord
#[derive(Collection)]
#[collection(serialization = transmog_bincode::Bincode)]
struct Foo {}
impl SerializedCollection for Foo {
type Contents = Foo;
type Format = $arg;
fn format() -> Self::Format {
$arg::default()
}
} |
Appart from the better In my test it formatted the code using |
This seams more like a future problem? If there is anything that can be done now for the macro let me know. |
I also added trybuild to test the error messages of derive macro. The macro does not check for name validity as the restrictions will be removed khonsulabs#143 (comment). closes khonsulabs#138 partially
There should probably be an example in the trait Collection docs right? |
Yes, I'd love to have the Colleciton trait have two examples -- the derive example and the equivalent manual implementation. I also think we should update all the examples to use the derive macro. I'm indifferent about whether unit tests should manually implement vs derive -- leaning towards derive. These refactors can be handled in separate PRs. |
It is no longer relevant. Spent some time thinking about it and this will end up being like View -- a Collection and CollectionSchema trait eventually. |
I also added trybuild to test the error messages of derive macro. The macro does not check for name validity as the restrictions will be removed khonsulabs#143 (comment). closes khonsulabs#138 partially
I also added trybuild to test the error messages of derive macro. The macro does not check for name validity as the restrictions will be removed khonsulabs#143 (comment). closes khonsulabs#138 partially
Collection currently has a lot of boilerplate code that could be reduced or eliminated by a derive macro. We should consider adding macros to help implement collections:
DefaultSerialization
can be auto-derived, or overridden with a parameter.[ByName, ...]
).Originally posted by @ModProg in #106 (comment)
Maybe other things could also be derived like
DefaultSerialization
.Maybe also Collection, but that would only be sensible for once without views etc. but at least for my use that would be really comftable :D.
If you want I would look into implementing the macro.
I have this a lot:
The text was updated successfully, but these errors were encountered: