Answers for "rust trait"

1

display trait rust

use std::fmt;

struct Point {
    x: i32,
    y: i32,
}

impl fmt::Display for Point {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "({}, {})", self.x, self.y)
    }
}

let origin = Point { x: 0, y: 0 };

assert_eq!(format!("The origin is: {}", origin), "The origin is: (0, 0)");Run
Posted by: Guest on March-16-2020
0

rust trait

pub trait Summary {
    fn summarize(&self) -> String;
}
Posted by: Guest on August-31-2021

Browse Popular Code Answers by Language