[Rust] Option Enum
pub enum Option2<T> {
None,
Some(T)
}
/**
impl is similar to typescript a class
with is_some method
*/
impl<T> Option2<T> {
pub fn is_some(&self) -> bool {
return match self {
Option2::None => false
Option2::Some(_) => true
}
}
}
fn main () {
let foo = Option2::Some(5);
if foo.is_some() {
let value = foo.unwrap();
}
}