Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Thing<'a> {
- thing_type: &'a ThingType,
- }
- struct ThingType {
- id: u32,
- }
- fn deserialize_thing<'a>(id: u32) -> Thing<'a> {
- // The function will own the value referred to by `thing_type`
- let thing_type = ThingType { id: id };
- Thing { thing_type: &thing_type }
- // thing_type goes out of scope and its value is dropped, but a `Thing` that
- // refers to it was returned. Hence we get a compiler error.
- }
- fn main() {
- let thing = deserialize_thing(42);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement