-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Explain in FromStr
s docs that you can't use a lifetime
#47757
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
@GuillaumeGomez is there any particular reason you nominated this issue? |
I really wish this would be fixed by introducing a lifetime in This would be a breaking change though, so maybe in a new Rust edition? |
Editions cannot make that kind of change; the stdlib cannot change signatures or remove anything.
… On Jun 28, 2018, at 1:18 PM, Ingvar Stepanyan ***@***.***> wrote:
I really wish this would be fixed by introducing a lifetime in FromStr trait instead. This would still allow to implement it for structures that don't borrow data, but would also enable it for structures that do.
This would be a breaking change though, so maybe in a new Rust edition?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
So there is no escape hatch for stdlib to fix already existing API issues like Rust editions fix syntactic ones? |
Would it still be a breaking change if the lifetime "defaulted" to Anyway, this is is off topic, it should definitely be documented for now. |
@oli-obk Yeah I was thinking about it too, but didn't suggest because it also requires syntactic change. |
How would this work? That would let you do this for |
Note quite, i'm not talking about the input: trait FromStr<'a = 'static> {
fn from_str<'b>(s: &'b str) -> Self where 'a: 'b;
}
struct Foo<'b>(&'b str);
struct Bar(String);
impl FromStr for Bar {
fn from_str(s: &str) -> Self {
Bar(s.to_owned())
}
}
impl<'c> FromStr<'c> for Foo<'c> {
fn from_str(s: &'c) -> Self {
Foo(s)
}
} Changing |
This isn't a language feature yet, I guess that's why I'm confused; I see now. Thanks :) |
…crum note that FromStr does not work for borrowed types Fixes rust-lang#47757
Inspired by https://www.reddit.com/r/rust/comments/7syu6z/where_do_you_declare_a_lifetime_for_fromstrerr/, but i've seen it crop up a few times. We should put something in the docs.
The text was updated successfully, but these errors were encountered: