Skip to content

shared string strip implemenetation #1876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2020

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