diff --git a/num-format/src/buffer.rs b/num-format/src/buffer.rs index c600d35..30eb307 100644 --- a/num-format/src/buffer.rs +++ b/num-format/src/buffer.rs @@ -78,7 +78,7 @@ impl Buffer { #[inline(always)] pub fn write_formatted(&mut self, n: &N, format: &F) -> usize where - F: Format, + F: Format + ?Sized, N: ToFormattedStr, { n.read_to_buffer(self, format) diff --git a/num-format/src/custom_format_builder.rs b/num-format/src/custom_format_builder.rs index 5d515f6..db18d42 100644 --- a/num-format/src/custom_format_builder.rs +++ b/num-format/src/custom_format_builder.rs @@ -70,7 +70,7 @@ impl CustomFormatBuilder { /// Sets all fields based on the provided format. pub fn format(mut self, value: &F) -> Self where - F: Format, + F: Format + ?Sized, { self.dec = DecString::new(value.decimal()); self.grp = value.grouping(); diff --git a/num-format/src/impls/integers.rs b/num-format/src/impls/integers.rs index 64c273e..d7dad4a 100644 --- a/num-format/src/impls/integers.rs +++ b/num-format/src/impls/integers.rs @@ -18,7 +18,7 @@ impl ToFormattedStr for u8 { #[inline(always)] fn read_to_buffer<'a, F>(&self, buf: &'a mut Buffer, _: &F) -> usize where - F: Format, + F: Format + ?Sized, { buf.write_with_itoa(*self) } @@ -31,7 +31,7 @@ macro_rules! impl_unsigned { #[inline(always)] fn read_to_buffer<'a, F>(&self, buf: &'a mut Buffer, format: &F) -> usize where - F: Format, + F: Format + ?Sized, { let n = *self as u128; run_core_algorithm(n, buf, format) @@ -62,7 +62,7 @@ macro_rules! impl_signed { #[inline(always)] fn read_to_buffer<'a, F>(&self, buf: &'a mut Buffer, format: &F) -> usize where - F: Format, + F: Format + ?Sized, { if self.is_negative() { let n = (!(*self as u128)).wrapping_add(1); // make positive by adding 1 to the 2s complement @@ -105,7 +105,7 @@ impl ToFormattedStr for NonZeroU8 { #[inline(always)] fn read_to_buffer<'a, F>(&self, buf: &'a mut Buffer, _: &F) -> usize where - F: Format, + F: Format + ?Sized, { buf.write_with_itoa(self.get()) } @@ -118,7 +118,7 @@ macro_rules! impl_non_zero { #[inline(always)] fn read_to_buffer<'a, F>(&self, buf: &'a mut Buffer, format: &F) -> usize where - F: Format, + F: Format + ?Sized, { let n = self.get() as u128; run_core_algorithm(n, buf, format) @@ -145,7 +145,7 @@ impl Sealed for NonZeroU128 {} #[inline(always)] fn run_core_algorithm(mut n: u128, buf: &mut Buffer, format: &F) -> usize where - F: Format, + F: Format + ?Sized, { // Bail out early if we can just use itoa // (i.e. if we don't have a separator) diff --git a/num-format/src/impls/num.rs b/num-format/src/impls/num.rs index 568b103..ffbfcc5 100644 --- a/num-format/src/impls/num.rs +++ b/num-format/src/impls/num.rs @@ -13,7 +13,7 @@ impl ToFormattedString for BigInt { #[inline(always)] fn read_to_io_writer(&self, mut w: W, format: &F) -> Result where - F: Format, + F: Format + ?Sized, W: io::Write, { match self.sign() { @@ -35,7 +35,7 @@ impl ToFormattedString for BigInt { #[inline(always)] fn read_to_fmt_writer(&self, mut w: W, format: &F) -> Result where - F: Format, + F: Format + ?Sized, W: fmt::Write, { match self.sign() { @@ -59,7 +59,7 @@ impl ToFormattedString for BigUint { #[inline(always)] fn read_to_io_writer(&self, w: W, format: &F) -> Result where - F: Format, + F: Format + ?Sized, W: io::Write, { let s = self.to_string(); @@ -70,7 +70,7 @@ impl ToFormattedString for BigUint { #[inline(always)] fn read_to_fmt_writer(&self, w: W, format: &F) -> Result where - F: Format, + F: Format + ?Sized, W: fmt::Write, { let s = self.to_string(); @@ -86,7 +86,7 @@ impl Sealed for BigUint {} fn io_algorithm(s: String, mut w: W, format: &F) -> Result where W: io::Write, - F: Format, + F: Format + ?Sized, { let separator = format.separator().into_str(); let grouping = format.grouping(); @@ -146,7 +146,7 @@ where fn fmt_algorithm(s: String, mut w: W, format: &F) -> Result where W: fmt::Write, - F: Format, + F: Format + ?Sized, { let separator = format.separator().into_str(); let grouping = format.grouping(); diff --git a/num-format/src/parsing.rs b/num-format/src/parsing.rs index 71e992b..9e29bc9 100644 --- a/num-format/src/parsing.rs +++ b/num-format/src/parsing.rs @@ -42,7 +42,7 @@ pub trait ParseFormatted { /// [Examples]: trait.ParseFormatted.html#examples fn parse_formatted(&self, format: &F) -> Result where - F: Format, + F: Format + ?Sized, N: FromFormattedStr; } @@ -52,7 +52,7 @@ where { fn parse_formatted(&self, format: &F) -> Result where - F: Format, + F: Format + ?Sized, N: FromFormattedStr, { FromFormattedStr::from_formatted_str(self.as_ref(), format) @@ -69,7 +69,7 @@ pub trait FromFormattedStr: Sealed + Sized { #[allow(missing_docs)] fn from_formatted_str(s: &str, format: &F) -> Result where - F: Format; + F: Format + ?Sized; } macro_rules! impl_from_formatted_str { @@ -77,7 +77,7 @@ macro_rules! impl_from_formatted_str { impl FromFormattedStr for $type { fn from_formatted_str(s: &str, format: &F) -> Result where - F: Format, + F: Format + ?Sized, { const BUF_LEN: usize = $max_len; let mut buf: [u8; BUF_LEN] = [0; BUF_LEN]; @@ -132,7 +132,7 @@ macro_rules! impl_from_formatted_str_non_zero { impl FromFormattedStr for $type { fn from_formatted_str(s: &str, format: &F) -> Result where - F: Format, + F: Format + ?Sized, { let n = s.parse_formatted::<_, $related_type>(format)?; let n = Self::new(n).ok_or_else(|| Error::parse_number(s))?; @@ -160,7 +160,7 @@ mod num { impl FromFormattedStr for $type { fn from_formatted_str(s: &str, format: &F) -> Result where - F: Format, + F: Format + ?Sized, { let mut buf = Vec::new(); diff --git a/num-format/src/to_formatted_str.rs b/num-format/src/to_formatted_str.rs index ed98871..e26dc62 100644 --- a/num-format/src/to_formatted_str.rs +++ b/num-format/src/to_formatted_str.rs @@ -11,5 +11,5 @@ pub trait ToFormattedStr: Sealed + Sized { #[doc(hidden)] fn read_to_buffer(&self, buf: &mut Buffer, format: &F) -> usize where - F: Format; + F: Format + ?Sized; } diff --git a/num-format/src/to_formatted_string.rs b/num-format/src/to_formatted_string.rs index 2db4c0b..af9f539 100644 --- a/num-format/src/to_formatted_string.rs +++ b/num-format/src/to_formatted_string.rs @@ -16,19 +16,19 @@ pub trait ToFormattedString: Sealed + Sized { #[doc(hidden)] fn read_to_fmt_writer(&self, w: W, format: &F) -> Result where - F: Format, + F: Format + ?Sized, W: fmt::Write; #[doc(hidden)] fn read_to_io_writer(&self, w: W, format: &F) -> Result where - F: Format, + F: Format + ?Sized, W: io::Write; /// Returns a string representation of the number formatted according to the provided format. fn to_formatted_string(&self, format: &F) -> String where - F: Format, + F: Format + ?Sized, { let mut s = String::with_capacity(MAX_BUF_LEN); let _ = self.read_to_fmt_writer(&mut s, format).unwrap(); @@ -43,7 +43,7 @@ where #[inline(always)] fn read_to_fmt_writer(&self, mut w: W, format: &F) -> Result where - F: Format, + F: Format + ?Sized, W: fmt::Write, { let mut buf = Buffer::default(); @@ -55,7 +55,7 @@ where #[inline(always)] fn read_to_io_writer(&self, mut w: W, format: &F) -> Result where - F: Format, + F: Format + ?Sized, W: io::Write, { let mut buf = Buffer::default(); diff --git a/num-format/src/write_formatted.rs b/num-format/src/write_formatted.rs index 9245f2e..68c5179 100644 --- a/num-format/src/write_formatted.rs +++ b/num-format/src/write_formatted.rs @@ -28,7 +28,7 @@ pub trait WriteFormatted { /// [`write_str`]: https://doc.rust-lang.org/stable/std/fmt/trait.Write.html#tymethod.write_str fn write_formatted(&mut self, n: &N, format: &F) -> Result where - F: Format, + F: Format + ?Sized, N: ToFormattedString; } @@ -37,7 +37,7 @@ macro_rules! impl_for_fmt_write { #[inline(always)] fn write_formatted(&mut self, n: &N, format: &F) -> Result where - F: Format, + F: Format + ?Sized, N: ToFormattedString, { n.read_to_fmt_writer(self, format) @@ -51,7 +51,7 @@ macro_rules! impl_for_io_write { #[inline(always)] fn write_formatted(&mut self, n: &N, format: &F) -> Result where - F: Format, + F: Format + ?Sized, N: ToFormattedString, { n.read_to_io_writer(self, format)