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!(Foo; "hello world");
assert_eq!(Hello.to_string(), "hello world");

Explicit and inline format args are supported.

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

const HI: &str = "hello"

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