From de113feb964a4844c5e884520018b395b817d095 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 8 Sep 2018 12:05:53 -0700 Subject: [PATCH] Add example of using itoa::Buffer --- src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8e624ef..2de79e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,6 +41,14 @@ pub fn fmt(mut wr: W, value: V) -> fmt::Result { } /// A safe API for formatting integers to text. +/// +/// # Example +/// +/// ```rust +/// let mut buffer = itoa::Buffer::new(); +/// let printed = buffer.format(1234); +/// assert_eq!(printed, "1234"); +/// ``` #[derive(Copy, Clone)] pub struct Buffer { bytes: [u8; I128_MAX_LEN], @@ -62,7 +70,7 @@ impl Buffer { } /// Print an integer into this buffer and return a reference to its string representation - /// within the buffer + /// within the buffer. pub fn format(&mut self, i: I) -> &str { i.write(self) }