Last active
July 25, 2024 05:42
-
-
Save knzai/458209b79fe061128fe35cd282c45b05 to your computer and use it in GitHub Desktop.
Things I still need reminders on when implementing models around Options etc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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