Skip to content

Instantly share code, notes, and snippets.

@bstrie
Created November 15, 2012 21:28
Show Gist options
  • Select an option

  • Save bstrie/4081403 to your computer and use it in GitHub Desktop.

Select an option

Save bstrie/4081403 to your computer and use it in GitHub Desktop.
impl<T: Copy Add<T,T>> Option<T> : Add<Option<T>, Option<T>> {
#[inline(always)]
pure fn add(other: &Option<T>) -> Option<T> {
match (self, *other) {
(None, None) => None,
(_, None) => self,
(None, _) => *other,
(Some(ref v1), Some(ref v2)) => Some(*v1 + *v2)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment