1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
//! A utility crate to make it easier to work with the //! [`Formatter`](core::fmt::Formatter) //! //! # Examples //! //! Nested debug help struct: //! //! ``` //! # #![cfg_attr(feature = "nightly", proc_macro_hygiene)] //! //! 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: //! //! ``` //! # #![cfg_attr(feature = "nightly", proc_macro_hygiene)] //! //! 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))); //! ``` #![no_std] pub use format_core::{ Binary, Debug, Display, LowerExp, LowerHex, Octal, Pointer, UpperExp, UpperHex, }; #[cfg(all(feature = "macro", not(feature = "nightly")))] use proc_macro_hack::proc_macro_hack; #[cfg(feature = "macro")] #[cfg_attr(all(feature = "macro", not(feature = "nightly")), proc_macro_hack)] pub use format_macro::lazy_format;