Skip to content

Instantly share code, notes, and snippets.

@arrdem
Last active July 10, 2017 00:14
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 arrdem/09898e41fde567e30bf1faa8a851dcaa to your computer and use it in GitHub Desktop.
Save arrdem/09898e41fde567e30bf1faa8a851dcaa to your computer and use it in GitHub Desktop.
struct MyVec<T>(T);
impl fmt::Display for MyVec<&Vec<i32>> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[");
for (i, el) in *(self.0).iter().enumerate() {
if i != 0 {
write!(f, ", ");
}
write!(f, "{}", el);
}
write!(f, "]")
}
}
fn main() {
let mut vec = vec![1, 2, 3];
{
let _vec = MyVec(&vec);
println!("{}", _vec);
}
vec.push(4);
{
let _vec = MyVec(&vec);
println!("{}", _vec);
}
}
-*- mode: cargo-process; default-directory: "~/scratch/" -*-
Cargo-Process started at Sun Jul 9 16:58:47
cargo bench
Compiling scratch v0.1.0 (file:///home/arrdem/scratch)
error[E0106]: missing lifetime specifier
--> src/main.rs:39:29
|
39 | impl fmt::Display for MyVec<&Vec<i32>> {
| ^ expected lifetime parameter
error: aborting due to previous error
error: Could not compile `scratch`.
To learn more, run the command again with --verbose.
Cargo-Process exited abnormally with code 101 at Sun Jul 9 16:58:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment