Created
November 15, 2012 20:25
-
-
Save bstrie/4081036 to your computer and use it in GitHub Desktop.
Overloading + on Option
This file contains hidden or 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
| compile_and_link: x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/libcore.so | |
| /media/linhaus/rust/src/libcore/option.rs:331:46: 331:48 error: mismatched types: expected `'a` but found `'b` (expected type parameter but found type parameter) | |
| /media/linhaus/rust/src/libcore/option.rs:331 (Some(v1), Some(v2)) => Some(v1 + v2) | |
| ^~ | |
| /media/linhaus/rust/src/libcore/option.rs:331:36: 332:9 error: mismatched types: expected `option::Option<'b>` but found `option::Option<'a>` (expected type parameter but found type parameter) | |
| /media/linhaus/rust/src/libcore/option.rs:331 (Some(v1), Some(v2)) => Some(v1 + v2) | |
| /media/linhaus/rust/src/libcore/option.rs:332 } | |
| error: aborting due to 2 previous errors | |
| make: *** [x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/libcore.so] Error 101 |
This file contains hidden or 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
| impl<R,T: Add<R,R>> 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(v1), Some(v2)) => Some(v1 + v2) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment