]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/bug-7183-generics.rs
a3bb02d1d0037835f8cb96ed1d03c7047b74e810
1 // Copyright 2013 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.
12 fn say(&self, s
:&str) -> String
;
13 fn hi(&self) -> String { hello(self) }
16 fn hello
<S
:Speak
>(s
:&S
) -> String
{
21 fn say(&self, s
:&str) -> String
{
22 format
!("{}: {}", s
, *self)
26 impl<T
: Speak
> Speak
for Option
<T
> {
27 fn say(&self, s
:&str) -> String
{
29 None
=> format
!("{} - none", s
),
30 Some(ref x
) => { format!("something!{}
", x.say(s)) }
37 assert_eq!(3.hi(), "hello
: 3".to_string());
38 assert_eq!(Some(Some(3)).hi(),
39 "something
!something
!hello
: 3".to_string());
40 assert_eq!(None::<int>.hi(), "hello
- none
".to_string());
42 assert_eq!(Some(None::<int>).hi(), "something
!hello
- none
".to_string());
43 assert_eq!(Some(3).hi(), "something
!hello
: 3".to_string());