Skip to content

Instantly share code, notes, and snippets.

@s-panferov
Last active August 29, 2015 14:13
Show Gist options
  • Save s-panferov/e9cafbec6ef5d097f041 to your computer and use it in GitHub Desktop.
Save s-panferov/e9cafbec6ef5d097f041 to your computer and use it in GitHub Desktop.
Rust problem

Hi all, can somebody help me to rewrite this piece of code with new unboxed closures:

struct Builder;
pub fn build(rules: |params: &mut Builder|) -> Builder {
    let mut builder = Builder::new();
    rules(&mut builder);

    builder
}

I tried to write like this, but I got a lifetime error:

pub fn build<F>(rules: F) -> Builder where F: FnOnce<(&mut Builder,), ()> {
    let mut builder = Builder::new();
    rules(&mut builder);

    builder
}

valico/src/builder.rs:48:59: 48:71 error: missing lifetime specifier [E0106]
valico/src/builder.rs:48     pub fn build<F>(rules: F) -> Builder where F: FnOnce<(&mut Builder,), ()> {
                                                                                   ^~~~~~~~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment