Docs.rs
  • format-0.2.4
    • format 0.2.4
    • Permalink
    • Docs.rs crate page
    • MIT OR Apache-2.0
    • Links
    • Homepage
    • Repository
    • crates.io
    • Source
    • Owners
    • kgv
    • Dependencies
      • format-core ^0.2.4 normal
      • format-macro ^0.2.4 normal optional
    • Versions
    • 33.33% of the crate is documented
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate format

format0.2.4

  • All Items

Sections

  • Examples

Crate Items

  • Macros
  • Structs

Crates

  • format

Crate format

Source
Expand description

A utility crate to make it easier to work with the Formatter

§Examples

Nested debug help struct:

use core::fmt::{Debug, Formatter, Result};
use format::lazy_format;
use std::format;

struct Foo {
    bar: [u32; 10],
}

impl Debug for Foo {
    fn fmt(&self, f: &mut Formatter) -> Result {
        let bar = lazy_format!(|f| f.debug_list().entries(&self.bar).finish());
        f.debug_struct("Foo")
            .field("bar", &format_args!("{}", bar))
            .finish()
    }
}

assert_eq!(
    "Foo { bar: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] }",
    format!("{:?}", Foo { bar: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] })
);

Control flow:

use core::fmt::{Debug, Formatter, Result};
use format::lazy_format;
use std::format;

struct Foo(usize);

impl Debug for Foo {
    fn fmt(&self, f: &mut Formatter) -> Result {
        let alternate = f.alternate();
        let bar = lazy_format!(|f| if alternate {
            write!(f, "{:#x}", self.0)
        } else {
            write!(f, "{:x}", self.0)
        });
        f.debug_tuple("Foo")
            .field(&format_args!("{}", bar))
            .finish()
    }
}

assert_eq!("Foo(75bcd15)", format!("{:?}", Foo(0123456789)));
assert_eq!("Foo(\n    0x75bcd15,\n)", format!("{:#?}", Foo(0123456789)));

Macros§

lazy_format
Lazy format macro

Structs§

Binary
A lazy format type that implements Binary as base format trait, Display and Debug as derivative from Binary
Debug
A lazy format type that implements Debug as base format trait
Display
A lazy format type that implements Display as base format trait, Debug as derivative from Display
LowerExp
A lazy format type that implements LowerExp as base format trait, Display and Debug as derivative from LowerExp
LowerHex
A lazy format type that implements LowerHex as base format trait, Display and Debug as derivative from LowerHex
Octal
A lazy format type that implements Octal as base format trait, Display and Debug as derivative from Octal
Pointer
A lazy format type that implements Pointer as base format trait, Display and Debug as derivative from Pointer
UpperExp
A lazy format type that implements UpperExp as base format trait, Display and Debug as derivative from UpperExp
UpperHex
A lazy format type that implements UpperHex as base format trait, Display and Debug as derivative from UpperHex

Results

Settings
Help
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.