Skip to content

Instantly share code, notes, and snippets.

@knzai
Last active July 25, 2024 05:42
Show Gist options
  • Save knzai/458209b79fe061128fe35cd282c45b05 to your computer and use it in GitHub Desktop.
Save knzai/458209b79fe061128fe35cd282c45b05 to your computer and use it in GitHub Desktop.
Things I still need reminders on when implementing models around Options etc
//take
OPTION.take() == mem::replace(OPTION, None)
//map
if let Some(value) = OPTION { *value = 42; } == OPTION.map(|value| *value = 36);
//Drop for boxed recursive options
impl Drop for Class {
fn drop(&mut self) {
let mut current = class_ref.take();
while let Some(mut boxed_ref) = current {
current = boxed_ref.next.take();
}
}
}
//Iter
pub trait Iterator {
type Item;
fn next(&mut self) -> Option<Self::Item>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment