You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[derive(Default, getset::Getters)]structA{#[get = "pub"]b:Option<B>,}#[derive(Default)]structB;fnmain(){let a = A::default();let b:Option<&B> = a.b();}
error[E0308]: mismatched types
--> src/main.rs:12:25
|
12 | let b: Option<&B> = a.b();
| ---------- ^^^^^
| | |
| | expected enum `Option`, found `&Option<B>`
| | help: you can convert from `&Option<T>` to `Option<&T>` using `.as_ref()`: `a.b().as_ref()`
| expected due to this
|
= note: expected enum `Option<&B>`
found reference `&Option<B>`
Getters that return &Option<T> (just like &Result<T>, etc.) are not really useful, as they require getter user to pollute code with .as_ref() everywhere. As alternative, having manual trivial getters like
is just another kind of boilerplate code pollution.
Can we do anything with this (and not some breaking change at the same time of course)?
I guess solution would likely require working with each such type separately (perhaps adding OptionGetters and #[get_option = "pub"], etc.), but still this would make this crate more coherent for users.
The text was updated successfully, but these errors were encountered:
I'd be happy to implement this as the default for Option<T> and/or Result<T, E>. Additionally, I would implement Vec<T> -> &[T], String -> &str. I cannot think of a reason why this would be preferred. This would be a breaking change though
Thanks for this awesome crate!
Getters that return
&Option<T>
(just like&Result<T>
, etc.) are not really useful, as they require getter user to pollute code with.as_ref()
everywhere. As alternative, having manual trivial getters likeis just another kind of boilerplate code pollution.
Can we do anything with this (and not some breaking change at the same time of course)?
I guess solution would likely require working with each such type separately (perhaps adding
OptionGetters
and#[get_option = "pub"]
, etc.), but still this would make this crate more coherent for users.The text was updated successfully, but these errors were encountered: