Skip to content

Instantly share code, notes, and snippets.

@sinhrks
Created November 16, 2016 10:43
Show Gist options
  • Save sinhrks/f01240ce8ba3a3a8baf8475bf65067e2 to your computer and use it in GitHub Desktop.
Save sinhrks/f01240ce8ba3a3a8baf8475bf65067e2 to your computer and use it in GitHub Desktop.
pub enum Option<T> {
    None,
    Some(T),
}
fn is_some(&self) -> bool 
fn is_none(&self) -> bool
fn as_ref(&self) -> Option<&T>
fn as_mut(&mut self) -> Option<&mut T>
fn unwrap(self) -> T
fn unwrap_or(self, def: T) -> T
fn unwrap_or_else<F>(self, f: F) -> T where F: FnOnce() -> T
fn unwrap_or_default(self) -> T
fn expect(self, msg: &str) -> T where F: FnOnce(T) -> U
fn map<U, F>(self, f: F) -> Option<U> 
fn map_or<U, F>(self, default: U, f: F) -> U where F: FnOnce(T) -> U
fn map_or_else<U, D, F>(self, default: D, f: F) -> U where D: FnOnce() -> U, F: FnOnce(T) -> U
fn ok_or<E>(self, err: E) -> Result<T, E>
fn ok_or_else<E, F>(self, err: F) -> Result<T, E> where F: FnOnce() -> E

fn and<U>(self, optb: Option<U>) -> Option<U>
fn and_then<U, F>(self, f: F) -> Option<U> where F: FnOnce(T) -> Option<U>

fn or(self, optb: Option<T>) -> Option<T>
fn or_else<F>(self, f: F) -> Option<T> where F: FnOnce() -> Option<T>
fn iter(&self) -> Iter<T>
fn iter_mut(&mut self) -> IterMut<T>
fn take(&mut self) -> Option<T>
pub enum Result<T, E> {
    Ok(T),
    Err(E),
}
fn is_ok(&self) -> bool
fn is_err(&self) -> bool
fn as_ref(&self) -> Result<&T, &E>
fn as_mut(&mut self) -> Result<&mut T, &mut E>
fn ok(self) -> Option<T>
fn err(self) -> Option<E>
fn unwrap(self) -> T
fn unwrap_or(self, optb: T) -> T
fn unwrap_or_else<F>(self, op: F) -> T where F: FnOnce(E) -> T
fn unwrap_err(self) -> E
fn unwrap_or_default(self) -> T
fn expect(self, msg: &str) -> T
fn map<U, F>(self, op: F) -> Result<U, E> where F: FnOnce(T) -> U
fn map_err<F, O>(self, op: O) -> Result<T, F> where O: FnOnce(E) -> F
fn and<U>(self, res: Result<U, E>) -> Result<U, E>
fn and_then<U, F>(self, op: F) -> Result<U, E> where F: FnOnce(T) -> Result<U, E>

fn or<F>(self, res: Result<T, F>) -> Result<T, F>
fn or_else<F, O>(self, op: O) -> Result<T, F> where O: FnOnce(E) -> Result<T, F>
fn iter(&self) -> Iter<T>
fn iter_mut(&mut self) -> IterMut<T>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment