kvfmt

Crates.iokvfmt
lib.rskvfmt
version0.1.5
sourcesrc
created_at2019-12-10 06:53:00.124384
updated_at2019-12-10 06:53:00.124384
descriptionA helper macro for stringifying variables into a key=value style string
homepagehttps://github.com/yaahc/kvfmt
repositoryhttps://github.com/yaahc/kvfmt
max_upload_size
id188144
size5,325
Jane Losare-Lusby (yaahc)

documentation

https://docs.rs/kvfmt

README

kvfmt="valuable"

Latest Version Rust Documentation

This library provides a convenient macro generating structured logging-esque strings with a minimalistic syntax.

[dependencies]
kvfmt = "0.1"

Example

use kvfmt::kvfmt;

fn main() {
    let dir = "/var/log";
    let paths = vec!["dmesg", "syslog"];

    assert_eq!(
        "dir=/var/log paths=[\"dmesg\", \"syslog\"]",
        kvfmt!(dir, ?paths)
    );
}

Details

  • This macro supports any number of identifiers, optionally prefixed with a ? to indicate that it should be formatted with the Debug trait rather than the Display trait which is the default.
    • kvfmt!(dir)format!("dir={}", dir)
    • kvfmt!(?dir)format!("dir={:?}", dir)

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Credits

A special thanks to Nika for helping me write the macro and David whose wonderful README style I continously steal for all of my projects.

Commit count: 1

cargo fmt