// Test generic type parameters
// Generic function
fn identity<T>(x: T) -> T {
x
}
// Generic struct
struct Box<T> {
value: T,
}
// Generic impl
impl<T> Box<T> {
fn new(value: T) -> Box<T> {
Box { value }
}
fn get(&self) -> &T {
&self.value
}
}
// Multiple type parameters
fn swap<A, B>(a: A, b: B) -> (B, A) {
(b, a)
}
fn main() {
// Test identity function with int
let x = identity(42)
println!("identity(42) = {}", x)
// Test identity function with string
let s = identity("hello")
println!("identity(string) = {}", s)
println!("Generic type parameters work! ✓")
}