I have a Rust struct T<'a> with Cow<'a, X> fields. I want to create .to_owned version of the struct and embed in another struct with a different lifetime. Lifetime of new struct could be shorter or longer. How do I do that?
If you want to use the `ToOwned` trait you should probably create an owned version of your struct with no lifetime instead of `Cow`
-
-
Yeah, I was hoping to abuse `Cow` to allow me to only have to define a single struct type. That's much simpler, as once you have 2 types, you need to express everything in terms of traits. Adds coding overhead. (Although it is arguably better.)
-
You really don't though. You can express everything in terms of `Cow<'a, Borrowed>` or `T: AsRef<Borrowed>`. It's no different than `String` or `str`.
- 2 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.