rust-itoa-Reintroduce-fmt.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. From 4c3501a1086fcea7ed9bd911d07aadcb23855780 Mon Sep 17 00:00:00 2001
  2. From: Maxime Devos <maximedevos@telenet.be>
  3. Date: Sun, 10 Apr 2022 17:54:00 +0000
  4. Subject: [PATCH] Revert "Delete fmt function"
  5. This reverts commit 9cf53f10832b202fa8f515352b4b1ebd7aa05e05,
  6. as rust-http@0.2 still uses this. (TODO inform rust-http)
  7. ---
  8. src/lib.rs | 28 ++++++++++++++++++++++++++++
  9. 1 file changed, 28 insertions(+)
  10. diff --git a/src/lib.rs b/src/lib.rs
  11. index c26bf35..c2bbd5e 100644
  12. --- a/src/lib.rs
  13. +++ b/src/lib.rs
  14. @@ -46,6 +46,34 @@ use core::{ptr, slice, str};
  15. /// A correctly sized stack allocation for the formatted integer to be written
  16. /// into.
  17. +#[cfg(feature = "std")]
  18. +extern crate std;
  19. +#[cfg(feature = "std")]
  20. +use std::{fmt, io};
  21. +
  22. +#[cfg(not(feature = "std"))]
  23. +use core::{fmt};
  24. +
  25. +/// Write integer to an `io::Write`.
  26. +#[cfg(feature = "std")]
  27. +#[inline]
  28. +pub fn write<W: io::Write, V: Integer>(mut wr: W, value: V) -> io::Result<usize> {
  29. + let mut buf = Buffer::new();
  30. + let s = buf.format(value);
  31. + match wr.write_all(s.as_bytes()) {
  32. + Ok(()) => Ok(s.len()),
  33. + Err(e) => Err(e),
  34. + }
  35. +}
  36. +
  37. +/// Write integer to an `fmt::Write`.
  38. +#[inline]
  39. +pub fn fmt<W: fmt::Write, V: Integer>(mut wr: W, value: V) -> fmt::Result {
  40. + let mut buf = Buffer::new();
  41. + wr.write_str(buf.format(value))
  42. +}
  43. +
  44. +/// A safe API for formatting integers to text.
  45. ///
  46. /// # Example
  47. ///
  48. --
  49. 2.34.0