Skip to content
a smaller, faster and panic-free alternative to core::fmt
Rust Shell Logos
Branch: master
Clone or download
bors and japaric Merge #17
17: stable v0.1.0 r=japaric a=japaric

- syn and quote dependencies have been bumped to v1.0

- everything now works on stable (thanks to proc-macro-hack)

Co-authored-by: Jorge Aparicio <jorge@japaric.io>
Latest commit f59b61d Nov 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github add CI May 1, 2019
ci fix ci Nov 17, 2019
macros stable v0.1.0 Nov 17, 2019
nopanic stable v0.1.0 Nov 17, 2019
src
tests stable v0.1.0 Nov 17, 2019
utils stable v0.1.0 Nov 17, 2019
write stable v0.1.0 Nov 17, 2019
.gitignore initial commit Apr 29, 2019
.travis.yml fix ci Nov 17, 2019
Cargo.toml stable v0.1.0 Nov 17, 2019
LICENSE-APACHE initial commit Apr 29, 2019
LICENSE-MIT initial commit Apr 29, 2019
README.md stable v0.1.0 Nov 17, 2019
cg.png add recursion test and update README May 8, 2019

README.md

μfmt

A (6-40x) smaller, (2-9x) faster and panic-free alternative to core::fmt

Call graph of formatting structs

Call graph of a program that formats some structs (generated using cargo-call-stack). Source code can be found at the bottom of this file. The program was compiled with -C opt-level=z.

API docs

Design goals

From highest priority to lowest priority

  • Optimized for binary size and speed (rather than for compilation time)

  • No dynamic dispatch in generated code

  • No panicking branches in generated code, when optimized

  • No recursion where possible

Features

  • Debug and Display-like traits

  • core::write!-like macro

  • A generic Formatter<'_, impl uWrite> instead of a single core::Formatter; the uWrite trait has an associated error type so each writer can choose its error type. For example, the implementation for std::String uses Infallible as its error type.

  • core::fmt::Formatter::debug_struct-like API

  • #[derive(uDebug)]

  • Pretty formatting ({:#?}) for uDebug

Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.34 and up. It might compile on older versions but that may change in any new patch release.

License

All source code (including code snippets) is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

Appendix

Formatting structs (snippet)

Full source code in nopanic/examples/struct.rs.

// ..

#[derive(Clone, Copy, uDebug)]
struct Pair {
    x: i32,
    y: i32,
}

static X: AtomicI32 = AtomicI32::new(0);
static Y: AtomicI32 = AtomicI32::new(0);

#[exception]
fn PendSV() {
    let x = X.load(Ordering::Relaxed);
    let y = Y.load(Ordering::Relaxed);

    uwrite!(&mut W, "{:?}", Braces {}).unwrap();
    uwrite!(&mut W, "{:#?}", Braces {}).unwrap();

    uwrite!(&mut W, "{:?}", Parens()).unwrap();
    uwrite!(&mut W, "{:#?}", Parens()).unwrap();

    uwrite!(&mut W, "{:?}", I32(x)).unwrap();
    uwrite!(&mut W, "{:#?}", I32(x)).unwrap();

    uwrite!(&mut W, "{:?}", Tuple(x, y)).unwrap();
    uwrite!(&mut W, "{:#?}", Tuple(x, y)).unwrap();

    let pair = Pair { x, y };
    uwrite!(&mut W, "{:?}", pair).unwrap();
    uwrite!(&mut W, "{:#?}", pair).unwrap();

    let first = pair;
    let second = pair;
    uwrite!(&mut W, "{:?}", Nested { first, second }).unwrap();
    uwrite!(&mut W, "{:#?}", Nested { first, second }).unwrap();
}

// ..
You can’t perform that action at this time.