Skip to content
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

Add support for enums to derive FromValue #113

Merged
merged 1 commit into from
Sep 26, 2020
Merged

Conversation

udoprog
Copy link
Collaborator

@udoprog udoprog commented Sep 26, 2020

This allows for enums to derive FromValue, like this:

#[derive(Debug, PartialEq, Eq, FromValue)]
enum Proxy {
    Unit,
    Tuple(String),
    Struct { field: String },
}

let proxy = rune! { Proxy => r#"
fn main() {
    enum Proxy { Unit, Tuple(a), Struct { field } }
    Proxy::Unit
}
"#};

assert_eq!(proxy, Proxy::Unit);

let proxy = rune! { Proxy => r#"
fn main() {
    enum Proxy { Unit, Tuple(a), Struct { field } }
    Proxy::Tuple("Hello World")
}
"#};

assert_eq!(proxy, Proxy::Tuple(String::from("Hello World")));

let proxy = rune! { Proxy => r#"
fn main() {
    enum Proxy { Unit, Tuple(a), Struct { field } }
    Proxy::Struct { field: "Hello World" }
}
"#};

assert_eq!(
    proxy,
    Proxy::Struct {
        field: String::from("Hello World")
    }
);

@udoprog udoprog added the enhancement New feature or request label Sep 26, 2020
@udoprog udoprog merged commit ff5d068 into master Sep 26, 2020
@udoprog udoprog deleted the fromvalue-enums branch September 26, 2020 11:13
@udoprog udoprog added the changelog Issue has been added to the changelog label Sep 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog Issue has been added to the changelog enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant