-
-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
//use beef::lean::Cow; -- compile error
use std::borrow::Cow;
struct Data<'a> {
data: String,
follower: Option<Cow<'a, str>>,
}
fn main() {
let mut data = Data {
data: "hello".into(),
follower: None,
};
data.follower = Cow::from(&data.data).into();
}In this code, follower has lifetime 'data and data has lifetime 'data
If i use beef::Cow – compiler tells me:
error[E0597]: `data.data` does not live long enough
--> src\main.rs:14:31
|
14 | data.follower = Cow::from(data.data.as_str()).into();
| ^^^^^^^^^^^^^^^^^^ borrowed value does not live long enough
15 | }
| -
| |
| `data.data` dropped here while still borrowed
| borrow might be used here, when `data` is dropped and runs the destructor for type `Data<'_>`
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels