Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion num-format/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Buffer {
#[inline(always)]
pub fn write_formatted<F, N>(&mut self, n: &N, format: &F) -> usize
where
F: Format,
F: Format + ?Sized,
N: ToFormattedStr,
{
n.read_to_buffer(self, format)
Expand Down
2 changes: 1 addition & 1 deletion num-format/src/custom_format_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl CustomFormatBuilder {
/// Sets all fields based on the provided format.
pub fn format<F>(mut self, value: &F) -> Self
where
F: Format,
F: Format + ?Sized,
{
self.dec = DecString::new(value.decimal());
self.grp = value.grouping();
Expand Down
12 changes: 6 additions & 6 deletions num-format/src/impls/integers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
Expand All @@ -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)
Expand All @@ -145,7 +145,7 @@ impl Sealed for NonZeroU128 {}
#[inline(always)]
fn run_core_algorithm<F>(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)
Expand Down
12 changes: 6 additions & 6 deletions num-format/src/impls/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl ToFormattedString for BigInt {
#[inline(always)]
fn read_to_io_writer<F, W>(&self, mut w: W, format: &F) -> Result<usize, io::Error>
where
F: Format,
F: Format + ?Sized,
W: io::Write,
{
match self.sign() {
Expand All @@ -35,7 +35,7 @@ impl ToFormattedString for BigInt {
#[inline(always)]
fn read_to_fmt_writer<F, W>(&self, mut w: W, format: &F) -> Result<usize, fmt::Error>
where
F: Format,
F: Format + ?Sized,
W: fmt::Write,
{
match self.sign() {
Expand All @@ -59,7 +59,7 @@ impl ToFormattedString for BigUint {
#[inline(always)]
fn read_to_io_writer<F, W>(&self, w: W, format: &F) -> Result<usize, io::Error>
where
F: Format,
F: Format + ?Sized,
W: io::Write,
{
let s = self.to_string();
Expand All @@ -70,7 +70,7 @@ impl ToFormattedString for BigUint {
#[inline(always)]
fn read_to_fmt_writer<F, W>(&self, w: W, format: &F) -> Result<usize, fmt::Error>
where
F: Format,
F: Format + ?Sized,
W: fmt::Write,
{
let s = self.to_string();
Expand All @@ -86,7 +86,7 @@ impl Sealed for BigUint {}
fn io_algorithm<F, W>(s: String, mut w: W, format: &F) -> Result<usize, io::Error>
where
W: io::Write,
F: Format,
F: Format + ?Sized,
{
let separator = format.separator().into_str();
let grouping = format.grouping();
Expand Down Expand Up @@ -146,7 +146,7 @@ where
fn fmt_algorithm<F, W>(s: String, mut w: W, format: &F) -> Result<usize, fmt::Error>
where
W: fmt::Write,
F: Format,
F: Format + ?Sized,
{
let separator = format.separator().into_str();
let grouping = format.grouping();
Expand Down
12 changes: 6 additions & 6 deletions num-format/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub trait ParseFormatted {
/// [Examples]: trait.ParseFormatted.html#examples
fn parse_formatted<F, N>(&self, format: &F) -> Result<N, Error>
where
F: Format,
F: Format + ?Sized,
N: FromFormattedStr;
}

Expand All @@ -52,7 +52,7 @@ where
{
fn parse_formatted<F, N>(&self, format: &F) -> Result<N, Error>
where
F: Format,
F: Format + ?Sized,
N: FromFormattedStr,
{
FromFormattedStr::from_formatted_str(self.as_ref(), format)
Expand All @@ -69,15 +69,15 @@ pub trait FromFormattedStr: Sealed + Sized {
#[allow(missing_docs)]
fn from_formatted_str<F>(s: &str, format: &F) -> Result<Self, Error>
where
F: Format;
F: Format + ?Sized;
}

macro_rules! impl_from_formatted_str {
($type:ty, $max_len:expr) => {
impl FromFormattedStr for $type {
fn from_formatted_str<F>(s: &str, format: &F) -> Result<Self, Error>
where
F: Format,
F: Format + ?Sized,
{
const BUF_LEN: usize = $max_len;
let mut buf: [u8; BUF_LEN] = [0; BUF_LEN];
Expand Down Expand Up @@ -132,7 +132,7 @@ macro_rules! impl_from_formatted_str_non_zero {
impl FromFormattedStr for $type {
fn from_formatted_str<F>(s: &str, format: &F) -> Result<Self, Error>
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))?;
Expand Down Expand Up @@ -160,7 +160,7 @@ mod num {
impl FromFormattedStr for $type {
fn from_formatted_str<F>(s: &str, format: &F) -> Result<Self, Error>
where
F: Format,
F: Format + ?Sized,
{
let mut buf = Vec::new();

Expand Down
2 changes: 1 addition & 1 deletion num-format/src/to_formatted_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ pub trait ToFormattedStr: Sealed + Sized {
#[doc(hidden)]
fn read_to_buffer<F>(&self, buf: &mut Buffer, format: &F) -> usize
where
F: Format;
F: Format + ?Sized;
}
10 changes: 5 additions & 5 deletions num-format/src/to_formatted_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ pub trait ToFormattedString: Sealed + Sized {
#[doc(hidden)]
fn read_to_fmt_writer<F, W>(&self, w: W, format: &F) -> Result<usize, fmt::Error>
where
F: Format,
F: Format + ?Sized,
W: fmt::Write;

#[doc(hidden)]
fn read_to_io_writer<F, W>(&self, w: W, format: &F) -> Result<usize, io::Error>
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<F>(&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();
Expand All @@ -43,7 +43,7 @@ where
#[inline(always)]
fn read_to_fmt_writer<F, W>(&self, mut w: W, format: &F) -> Result<usize, fmt::Error>
where
F: Format,
F: Format + ?Sized,
W: fmt::Write,
{
let mut buf = Buffer::default();
Expand All @@ -55,7 +55,7 @@ where
#[inline(always)]
fn read_to_io_writer<F, W>(&self, mut w: W, format: &F) -> Result<usize, io::Error>
where
F: Format,
F: Format + ?Sized,
W: io::Write,
{
let mut buf = Buffer::default();
Expand Down
6 changes: 3 additions & 3 deletions num-format/src/write_formatted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F, N>(&mut self, n: &N, format: &F) -> Result<usize, io::Error>
where
F: Format,
F: Format + ?Sized,
N: ToFormattedString;
}

Expand All @@ -37,7 +37,7 @@ macro_rules! impl_for_fmt_write {
#[inline(always)]
fn write_formatted<F, N>(&mut self, n: &N, format: &F) -> Result<usize, io::Error>
where
F: Format,
F: Format + ?Sized,
N: ToFormattedString,
{
n.read_to_fmt_writer(self, format)
Expand All @@ -51,7 +51,7 @@ macro_rules! impl_for_io_write {
#[inline(always)]
fn write_formatted<F, N>(&mut self, n: &N, format: &F) -> Result<usize, io::Error>
where
F: Format,
F: Format + ?Sized,
N: ToFormattedString,
{
n.read_to_io_writer(self, format)
Expand Down