hunter / explode

Clone this repo

Branches
View All
  • 844b8b8 Fix bug with conflicting names by Hunter Praska at 2018-06-03 02:34:27 -05:00

  • f782806 Make structs public by Hunter Praska at 2017-07-26 09:38:37 -05:00

  • 3fd8e2b Make portions of api public by Hunter Praska at 2017-07-23 10:56:39 -05:00

  • 411ef0c Initial commit by Hunter Praska at 2017-07-23 10:40:57 -05:00

View Log

Explode

Generates an explode function for enums that returns a struct version of the enum.

Example

enum E {
    A(String),
    B { x: i32 },
    C,
}

type _A<'a> = (&'a String);

struct _B<'a> {
    x: &'a i32,
}

struct _C;

struct _explode_E<'a> {
    A: Option<_A<'a>>,
    B: Option<_B<'a>>,
    C: Option<_C>,
}

impl E {
    fn explode(&self) -> _explode_E {
        match self {
            &E::A(ref x) => _explode_E { A: Some(x), B: None, C: None },
            &E::B { ref x } => _explode_E { A: None, B: Some(_B { x }), C: None },
            &E::C => _explode_E { A: None, B: None, C: Some(_C) },
        }
    }
}