Skip to content

format! macros analogue #18

@DevNulPavel

Description

@DevNulPavel

Hello, is it possible to create format! macros analogue?

It is often i'm writing similar code like

use std::fmt::Write;
let mut buf = smallstr::SmallString::<[u8;64]>::new();
write!(&mut buf, "test_config_{}.conf", uuid).unwrap();

But it can be rewritten using macros like

macro_rules! format_small {
    ($len:expr, $($arg:tt)*) => {
        {
            use std::fmt::Write;
            let mut buf = smallstr::SmallString::<[u8; $len]>::new();
            buf.write_fmt(::core::format_args!($($arg)*)).unwrap();
            buf
        }
    };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions