diff --git a/library/core/src/option.rs b/library/core/src/option.rs index b6aa2c6697123..4e08c4933684b 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -135,7 +135,7 @@ use crate::iter::{FromIterator, FusedIterator, TrustedLen}; use crate::pin::Pin; use crate::{ convert, fmt, hint, mem, - ops::{self, Deref, DerefMut}, + ops::{self, Add, Deref, DerefMut}, }; /// The `Option` type. See [the module level documentation](self) for more. @@ -1260,6 +1260,19 @@ impl Default for Option { } } +#[stable(feature = "option_add", since = "1.46.0")] +impl> Add for Option { + type Output = Self; + + fn add(self, other: Self) -> Self::Output { + match (self, other) { + (a, None) => a, + (None, b) => b, + (Some(a), Some(b)) => Some(a.add(b)), + } + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for Option { type Item = T;