Skip to content

Instantly share code, notes, and snippets.

@JosiahParry
Created July 6, 2025 17:01
Show Gist options
  • Save JosiahParry/3d56d94bc40a345973f93dc105b65db2 to your computer and use it in GitHub Desktop.
Save JosiahParry/3d56d94bc40a345973f93dc105b65db2 to your computer and use it in GitHub Desktop.
pub trait Coalesce {
type Item;
fn coalesce(self, other: Option<Self::Item>) -> Option<Self::Item>;
}
impl<T> Coalesce for Option<T> {
type Item = T;
fn coalesce(self, other: Option<T>) -> Option<T> {
self.or(other)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment