impl_more

Macro impl_display

Source
macro_rules! impl_display {
    ($ty:ty; $format:literal) => { ... };
    ($ty:ty; $format:literal, $($args:expr),+) => { ... };
    ($ty:ty; $format:literal, $($args:expr),+ ,) => { ... };
}
Expand description

Implements Display for structs using a format!-like string constructor.

ยงExamples

Display implementation can be just a string literal.

struct Hello;
impl_more::impl_display!(Hello; "hello world");
assert_eq!(Hello.to_string(), "hello world");

Explicit and inline format args are supported.

struct Hello2;
impl_more::impl_display!(Hello2; "hello world {}", 2);
assert_eq!(Hello2.to_string(), "hello world 2");

const HI: &str = "hello";

struct Hello3;
impl_more::impl_display!(Hello3; "{HI} world");
assert_eq!(Hello3.to_string(), "hello world");