« first day (3529 days earlier)      last day (180 days later) » 

 
5 hours later…
06:17
Hi. Basic noob question here. I have 2 structs, Foo and OwnedFoo and I'd like to convet from the second one to the first one: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f7d46d97e2930c10a25236f6f3318823
Is there a way to avoid the `(&owned)` everytime I convert ?
 
2 hours later…
08:33
Interesting, I got it by that very issue just yesterday. It was surprising to realise that while generally in Rust you get Deref automatically, it doesn't seem to apply to into/try_into calls.
There are two mitigating factors. Firstly, if you already have a reference to owned, then it'll just work, so the problem is limited to scopes where you have an owned owned. Secondly, you can instead use "Foo::try_from(&owned)" which I personally find more visually pleasing.
Yeah, I looked into the traits like Deref and found nothing matching the need
And of course, you can perfectly write an inherent "as_foo()" method on Owned.
Foo::from(&owned) looks better than (&owned).into(), yes. I think I'll use that.
I asked because I was feeling I was missing an obvious trait or something
If there is a trait for that, we're both missing it :'(
Note that if there was a trait, people would wonder why they can't chain it, so maybe it's better without it unless we get new borrow rules
 
6 hours later…
14:51
@Stargateur Not sure it's better. Syntactically it's prettier but ...
@Stargateur This one is good. That's the kind of standard trait I was looking for. Too bad it's not standard :(
we need a std 2.0 with gats
Too bad the naming would make it confusing
Not sure I'll use it, but it's interesting
15:06
@DenysSéguret I would prefer an inherent method for that. The From/Into impl can still exist if you need it for generic reasons, but a simple .to_ref would go a long way I think.

« first day (3529 days earlier)      last day (180 days later) »