Last active
August 29, 2015 13:56
-
-
Save chuckremes/9124725 to your computer and use it in GitHub Desktop.
This file contains 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
struct Helper<T> { | |
field1: T | |
} | |
impl<T> Helper<T> { | |
fn new (foo: T) -> Helper<T> { | |
Helper { field1: foo } | |
} | |
fn add_one<T: Add> (&mut self, value: T) { | |
self.field1 += value; | |
} | |
} | |
fn main () { | |
let mut helper: Helper<int> = Helper::new(3); | |
println!("helper.field value is {}", helper.field1); | |
helper.add_one(2); | |
println!("helper.field value is {}", helper.field1); | |
} |
This file contains 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
cremes$ rustc foo.rs | |
foo.rs:11:16: 11:19 error: wrong number of type arguments: expected 2 but found 0 | |
foo.rs:11 fn add_one<T: Add> (&mut self, value: T) { | |
^~~ | |
task 'rustc' failed at 'explicit failure', /opt/local/var/macports/build/_opt_mports_dports_lang_rust/rust/work/rust-0.9/src/libsyntax/diagnostic.rs:41 | |
task '<main>' failed at 'explicit failure', /opt/local/var/macports/build/_opt_mports_dports_lang_rust/rust/work/rust-0.9/src/librustc/lib.rs:453 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment