Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum Switch {
- ON,
- OFF
- }
- impl<'a> From<&'a str> for Switch {
- fn from(s: &str) -> Self {
- match s {
- "ON" | "on" => Switch::ON,
- "OFF" | "off" => Switch::OFF,
- _ => panic!("Invalid enumerator: {}", s)
- }
- }
- }
- fn main() {
- let on_owned = String::from("ON");
- let ref_to_owned = &on_owned;
- let on = Switch::from(&**ref_to_owned);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement