Skip to content

Conversation

@youknowone
Copy link
Member

No description provided.

@youknowone
Copy link
Member Author

youknowone commented Apr 25, 2020

I tried to use fn() but it is not easy to solve lifetime error. Any help would be appreciated.

    fn py_strip<'a, S>(
        &'a self,
        chars: OptionalOption<S>,
        func_chars: fn(&'a Self, &'a Self) -> &'a Self,
        func_default: fn(&'a Self) -> &'a Self,
    ) -> &'a Self
    where
        S: 'a + PyCommonStringWrapper<Self>,
    {
        let chars = chars.flat_option();
        match chars {
            Some(chars) => func_chars(self, chars.as_ref()),
            None => func_default(self),
        }
    }
error[E0597]: `chars` does not live long enough
   --> vm/src/obj/pystr.rs:186:45
    |
175 |     fn py_strip<'a, S>(
    |                 -- lifetime `'a` defined here
...
186 |             Some(chars) => func_chars(self, chars.as_ref()),
    |                            -----------------^^^^^----------- `chars` dropped here while still borrowed
    |                            |                |
    |                            |                borrowed value does not live long enough
    |                            argument requires that `chars` is borrowed for `'a`

@youknowone youknowone merged commit d3449ae into RustPython:master Apr 25, 2020
@youknowone youknowone deleted the share-strip branch April 25, 2020 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants