Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created November 11, 2019 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/de2947cd737c7181880da7791e911f4c to your computer and use it in GitHub Desktop.
Save rust-play/de2947cd737c7181880da7791e911f4c to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
pub enum Index<'a> {
S(&'a str),
I(usize),
}
impl<'a> From<&'a str> for Index<'a> {
fn from(s: &'a str) -> Self {
Self::S(s)
}
}
impl<'a> From<String> for Index<'a> {
fn from(s: String) -> Self {
Self::S(s.as_str())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment