Open Arnavion opened 7 years ago
I would definitely be happy to support better defaults for common return types. Some possibilities:
String
→ &str
Vec<T>
→ &[Recurse!(T)]
Option<T>
→ Option<Recurse!(T)>
T
→ &T
(if not a Copy
type in the standard library?)…where Recurse!
means "apply this rule recursively on the contained type". The trick is dealing with Copy
versus !Copy
. I wonder if there's a trait somewhere in the standard lib which allows us to distinguish between these cases?
For example, to allow a getter for a
foo: Foo
field to return&Bar
instead of&Foo
. For example a#[getter(return = "&Bar")]
field attribute. Of course this will only work for deref-coercible types since the body of the getter will still be&self.foo
.It might also be good to have some overrides like this as part of the base crate. For example, my own macro has overrides for
String -> &str
,Option<String> -> Option<&str>
,Option<T> -> Option<&T>
,Vec<String> -> Vec<&str>
, etc.