Skip to content

Instantly share code, notes, and snippets.

@chuckremes
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuckremes/9124725 to your computer and use it in GitHub Desktop.
Save chuckremes/9124725 to your computer and use it in GitHub Desktop.
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);
}
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