Title: Theory / Unimportant / CS / Programming / Rust / Library / Option
Tags: automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Page: https://doc.rust-lang.org/std/option/

Typ: Option<T>
Page: https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html
Language: Rust
Chapter: 6
Variables: T a type
Value: None
Value2: Some(T)
Library: std::option

Instruction: opt.is_none()
Returns: opt == None
Variables: opt: Option<T>

Instruction: opt.is_some()
Returns: opt != None
Variables: opt: Option<T>

Instruction: opt.as_ref()
Returns: opt: Option<&T>
Variables: opt: &Option<T>

Instruction: opt.as_mut()
Returns: opt: Option<&mut T>
Variables: opt: &mut Option<T>

Instruction: opt.as_deref()
Returns: opt: Option<&T::Target>
Variables: opt: &Option<T>

Instruction: pin_opt.as_pin_ref()
Returns: pin_opt: Option<Pin<&T>>
Variables: pin_opt: Pin<&Option<T>>

Instruction: pin_opt.as_pin_mut()
Returns: pin_opt: Option<Pin<&mut T>>
Variables: pin_opt: Pin<&mut Option<T>>

Instruction: optional.as_deref_mut()
Returns: optional: Option<&mut T::Target>
Variables: optional: Option<T>

Instruction: optional.filter(pred)
Returns: optional if pred(optional.unwrap()), else None
Variables: optional: Option<T>

Instruction: optional.flatten()
Returns: optional: Option<T>
Variables: optional: Option<Option<T>>

Instruction: optional.map(f)
Returns: apply f to optional if it is Some, else None
Variables: optional: Option<T>

Instruction: optional.foo_or(
  args,
  none_value
)
Returns: same as optional.foo(  args) on Some value.
none_value on None
Variables: optional: Option<T>

Instruction: optional.foo_or_else(
  args,
  none_fn
)
Returns: same as optional.foo(  args) on Some value.
none_fn(  ) on None
Variables: optional: Option<T>

Instruction: optional_1.zip(optional_2)
Returns: None if any optional is None
Some((optional_1.unwrap(), optional_2.unwrap()) otherwise
Variables: optional_1: Option<T_1>
optional_2: Option<T_2>

Instruction: optional.transpose()
Returns: optional: Result<Option<T>>
Variables: optional: Option<Result<T>>

Instruction: optional.ok_or(err)
Returns: Err(err) if None
Ok(optional.unwrap) if Some
Variables: optional: Option<T>

Instruction: optional_1 and optional_2
Returns: None if any optional is None
optional_2 if both optional are Some.
Variables: optional_1: Option<T_1>
optional_2: Option<T_2>

Instruction: optional_1 or optional_2
Returns: if optional_1 is Some, then optional_1 else optional_2
Variables: optional_1: Option<T_1>
optional_2: Option<T_2>

Instruction: optional_1 xor optional_2
Returns: None if both are None or both are Some
The only Some value otherwise
Variables: optional_1: Option<T_1>
optional_2: Option<T_2>

Instruction: optional.and_then(f)
Returns: None to None
f(optional.unwrap()) otherwise
Variables: optional: Option<T>

Instruction: optional.or_else(f)
Returns: Some(x) to itself
f() otherwise
Variables: optional: Option<T>

Question: What is the order on Optional<T>
Answer: None is smallest value. Unwrapped order on Some's
Page: https://doc.rust-lang.org/std/option/
Variables: optional_1: Option<T_1>
optional_2: Option<T_2>

Instruction: optional.into_iter/iter/iter_mut()
Returns: An iterator returning the wrapped value or nothing
Variables: optional: Option<T>

Instruction: optional.into_iter()
Returns: None if any emitted value is None. Some<Array<>> of emitted values otherwise
Variables: optional: IntoIter<Option<T>>

Instruction: iter_optional.sum()
Returns: None if any emitted value is None. Their sum/product otherwise
Variables: iter_optional: IntoIter<Option<T>>

Instruction: iter_optional.sum/product()
Returns: None if any emitted value is None. Their sum/product otherwise
Variables: iter_optional: IntoIter<Option<T>>

Instruction: optional.unwrap()
Effect: Panic if none
Returns: the value if Some
Variables: optional: Option<T>
Intuition: Don't use, it can panic

Instruction: optional.unwrap_or_default()
Returns: the value if Some.
T::default otherwise
Variables: optional: Option<T>

Instruction: optional.expect(msg)
Effect: Panic with msg if None
Returns: the value if Some.
Variables: optional: Option<T>

Instruction: optional.replace(value)
Effect: set optional to Some(value)
Returns: the previous value of optional
Variables: optional: Option<T>

Instruction: optional.take()
Effect: set optional to None
Returns: the previous value of optional
Variables: optional: Option<T>

Instruction: optional.get_or_insert_default()
Returns: todo when not unstable
Variables: optional: Option<T>

Instruction: optional.get_or_insert_with(f)
Returns: todo when not unstable
Variables: optional: Option<T>

Instruction: optional.get_or_insert(value)
Returns: todo when not unstable
Variables: optional: Option<T>

Instruction: optional.insert(value)
Returns: todo when not unstable
Variables: optional: Option<T>