1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(try_trait)]
20 impl<U, V> Try for MyResult<U, V> {
24 fn from_ok(u: U) -> MyResult<U, V> {
28 fn from_error(e: V) -> MyResult<U, V> {
32 fn into_result(self) -> Result<U, V> {
34 MyResult::Awesome(u) => Ok(u),
35 MyResult::Terrible(e) => Err(e),
40 fn f(x: i32) -> Result<i32, String> {
49 fn g(x: i32) -> MyResult<i32, String> {
51 MyResult::Terrible("Hello".to_owned())
54 fn h() -> MyResult<i32, String> {
55 let a: Result<i32, &'static str> = Err("Hello");
60 fn i() -> MyResult<i32, String> {
61 let a: MyResult<i32, &'static str> = MyResult::Terrible("Hello");
67 assert!(f(0) == Ok(42));
68 assert!(f(10) == Err("Hello".to_owned()));