Skip to content

Commit f203852

Browse files
committed
Revert "Remove dependency on itoa"
This reverts commit 26cf0ac.
1 parent 45b9932 commit f203852

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ time-macros = { path = "time-macros", version = "=0.2.24" }
99

1010
criterion = { version = "0.5.1", default-features = false }
1111
deranged = { version = "0.5.2", features = ["powerfmt"] }
12+
itoa = "1.0.1"
1213
js-sys = "0.3.58"
1314
libc = "0.2.98"
1415
num-conv = "0.1.0"

time/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ rustdoc-args = ["--generate-link-to-definition"]
3232
[features]
3333
default = ["std"]
3434
alloc = ["serde?/alloc"]
35-
formatting = ["std", "time-macros?/formatting"]
35+
formatting = ["dep:itoa", "std", "time-macros?/formatting"]
3636
large-dates = ["time-macros?/large-dates"]
3737
local-offset = ["std", "dep:libc", "dep:num_threads"]
3838
macros = ["dep:time-macros"]
@@ -52,6 +52,7 @@ wasm-bindgen = ["dep:js-sys"]
5252
# feature gate.
5353
[dependencies]
5454
deranged = { workspace = true }
55+
itoa = { workspace = true, optional = true }
5556
num-conv = { workspace = true }
5657
powerfmt = { workspace = true }
5758
quickcheck = { workspace = true, optional = true }

time/src/formatting/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod iso8601;
55

66
use core::num::NonZero;
77
use std::io;
8-
use std::string::ToString;
98

109
use num_conv::prelude::*;
1110

@@ -142,7 +141,7 @@ pub(crate) fn format_float(
142141
#[inline]
143142
pub(crate) fn format_number<const WIDTH: u8>(
144143
output: &mut (impl io::Write + ?Sized),
145-
value: impl ToString + DigitCount + Copy,
144+
value: impl itoa::Integer + DigitCount + Copy,
146145
padding: modifier::Padding,
147146
) -> Result<usize, io::Error> {
148147
match padding {
@@ -158,13 +157,13 @@ pub(crate) fn format_number<const WIDTH: u8>(
158157
#[inline]
159158
pub(crate) fn format_number_pad_space<const WIDTH: u8>(
160159
output: &mut (impl io::Write + ?Sized),
161-
value: impl ToString + DigitCount + Copy,
160+
value: impl itoa::Integer + DigitCount + Copy,
162161
) -> Result<usize, io::Error> {
163162
let mut bytes = 0;
164163
for _ in 0..(WIDTH.saturating_sub(value.num_digits())) {
165164
bytes += write(output, b" ")?;
166165
}
167-
bytes += write(output, value.to_string().as_bytes())?;
166+
bytes += write(output, itoa::Buffer::new().format(value).as_bytes())?;
168167
Ok(bytes)
169168
}
170169

@@ -174,13 +173,13 @@ pub(crate) fn format_number_pad_space<const WIDTH: u8>(
174173
#[inline]
175174
pub(crate) fn format_number_pad_zero<const WIDTH: u8>(
176175
output: &mut (impl io::Write + ?Sized),
177-
value: impl ToString + DigitCount + Copy,
176+
value: impl itoa::Integer + DigitCount + Copy,
178177
) -> Result<usize, io::Error> {
179178
let mut bytes = 0;
180179
for _ in 0..(WIDTH.saturating_sub(value.num_digits())) {
181180
bytes += write(output, b"0")?;
182181
}
183-
bytes += write(output, value.to_string().as_bytes())?;
182+
bytes += write(output, itoa::Buffer::new().format(value).as_bytes())?;
184183
Ok(bytes)
185184
}
186185

@@ -190,9 +189,9 @@ pub(crate) fn format_number_pad_zero<const WIDTH: u8>(
190189
#[inline]
191190
pub(crate) fn format_number_pad_none(
192191
output: &mut (impl io::Write + ?Sized),
193-
value: impl ToString + Copy,
192+
value: impl itoa::Integer + Copy,
194193
) -> Result<usize, io::Error> {
195-
write(output, value.to_string().as_bytes())
194+
write(output, itoa::Buffer::new().format(value).as_bytes())
196195
}
197196

198197
/// Format the provided component into the designated output. An `Err` will be returned if the

0 commit comments

Comments
 (0)