AI Features

Display

We'll cover the following...

Using the format macro, I can write a function that turns an i32 into a String:

Rust 1.40.0
fn stringy(x: i32) -> String {
format!("{}", x)
}
fn main() {
assert_eq!(stringy(42), "42".to_owned());
println!("Success!");
}

But we’re all about type parameters these days. Can we generalize this to any type T?

fn stringy<T>(x: T) -> String {
format!("{}", x)
}

Not like that apparently:

 ...