Skip to content

Instantly share code, notes, and snippets.

@sahandevs
Created March 12, 2022 06:21
Show Gist options
  • Select an option

  • Save sahandevs/13e3409541cce4443c406c11a4b553a9 to your computer and use it in GitHub Desktop.

Select an option

Save sahandevs/13e3409541cce4443c406c11a4b553a9 to your computer and use it in GitHub Desktop.

You can use pattern matching in function parameters. examples:

struct S { 
    field1: String,
    fields2: usize,
}

fn test_fn(S { field1, .. }: S) {
    println!("{}", field1);
}


enum Id {
    V1(usize),
    V2(usize),
}

fn test_fn((Id::V1(id) | Id::V2(id)) : Id) {
    println!("{}", id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment