Обобщенные типы

//There are no classes in Rust
struct Size<T> {
    width: T,
    height: T
}

impl<Tstd::fmt::DebugSize<T> {
    fn new(width: T, height: T) -> Size<T> {
        Size {
            width: width, height: height
        }
    }

    fn as_text(&self) -> String {
        format!("[{:?}{:?}]",
            self.widthself.height)
    }


let size_int = Size::new(58);
let text_int = size_int.as_text();
//text_int is "[5; 8]"

let size_float = Size::new(3.71.58);
let text_float = size_float.as_text();
//text_float is "[3.7; 1.58]"

println!("text_int is {text_int}");
println!("text_float is {text_float}");