From d553933e00de0b37b5864a9ea47022098fc31dc3 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 30 Nov 2023 16:55:03 -0800 Subject: [PATCH 1/3] Change StringM Debug, String, and Debug representations to escaped --- lib/xdrgen/generators/rust/src/types.rs | 30 ++++++++++++++----- .../block_comments.x/MyXDR.rs | 30 ++++++++++++++----- .../generator_spec_rust/const.x/MyXDR.rs | 30 ++++++++++++++----- .../generator_spec_rust/enum.x/MyXDR.rs | 30 ++++++++++++++----- .../generator_spec_rust/nesting.x/MyXDR.rs | 30 ++++++++++++++----- .../generator_spec_rust/optional.x/MyXDR.rs | 30 ++++++++++++++----- .../generator_spec_rust/struct.x/MyXDR.rs | 30 ++++++++++++++----- .../generator_spec_rust/test.x/MyXDR.rs | 30 ++++++++++++++----- .../generator_spec_rust/union.x/MyXDR.rs | 30 ++++++++++++++----- .../block_comments.x/MyXDR.rs | 30 ++++++++++++++----- .../const.x/MyXDR.rs | 30 ++++++++++++++----- .../enum.x/MyXDR.rs | 30 ++++++++++++++----- .../nesting.x/MyXDR.rs | 30 ++++++++++++++----- .../optional.x/MyXDR.rs | 30 ++++++++++++++----- .../struct.x/MyXDR.rs | 30 ++++++++++++++----- .../test.x/MyXDR.rs | 30 ++++++++++++++----- .../union.x/MyXDR.rs | 30 ++++++++++++++----- 17 files changed, 391 insertions(+), 119 deletions(-) diff --git a/lib/xdrgen/generators/rust/src/types.rs b/lib/xdrgen/generators/rust/src/types.rs index b64c54fb1..9b332d3e3 100644 --- a/lib/xdrgen/generators/rust/src/types.rs +++ b/lib/xdrgen/generators/rust/src/types.rs @@ -1635,6 +1635,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1680,7 +1691,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1692,7 +1705,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1702,7 +1717,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1750,24 +1766,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs b/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs index cbd950c3d..323dc5e5d 100644 --- a/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust/const.x/MyXDR.rs b/spec/output/generator_spec_rust/const.x/MyXDR.rs index 18b47560b..b04843d2b 100644 --- a/spec/output/generator_spec_rust/const.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/const.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust/enum.x/MyXDR.rs b/spec/output/generator_spec_rust/enum.x/MyXDR.rs index 5066acafb..d4b1468c8 100644 --- a/spec/output/generator_spec_rust/enum.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/enum.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust/nesting.x/MyXDR.rs b/spec/output/generator_spec_rust/nesting.x/MyXDR.rs index a71bb0182..aee6c525b 100644 --- a/spec/output/generator_spec_rust/nesting.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/nesting.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust/optional.x/MyXDR.rs b/spec/output/generator_spec_rust/optional.x/MyXDR.rs index c54e9bc24..4f95cb855 100644 --- a/spec/output/generator_spec_rust/optional.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/optional.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust/struct.x/MyXDR.rs b/spec/output/generator_spec_rust/struct.x/MyXDR.rs index d36ed07c5..aa7c9978b 100644 --- a/spec/output/generator_spec_rust/struct.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/struct.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust/test.x/MyXDR.rs b/spec/output/generator_spec_rust/test.x/MyXDR.rs index d1f590d66..ba624636e 100644 --- a/spec/output/generator_spec_rust/test.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/test.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust/union.x/MyXDR.rs b/spec/output/generator_spec_rust/union.x/MyXDR.rs index 2cf3d387c..b270e45c4 100644 --- a/spec/output/generator_spec_rust/union.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/union.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs index cbd950c3d..323dc5e5d 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs index 18b47560b..b04843d2b 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs index 31f640596..dadc93f9c 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs index 1c56daf4e..b31762e6a 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs index e7606d38b..2ea5d39a3 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs index c569fd2de..e37dc6a20 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs index 08c843587..de6cc45a0 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs index a6b641f07..6175dbdf5 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs @@ -1645,6 +1645,17 @@ impl WriteXdr for BytesM { // StringM ------------------------------------------------------------------------ +/// A string type that contains arbitrary bytes. +/// +/// Convertible, fallibly, to/from a Rust UTF-8 String using +/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`]. +/// +/// Convertible, lossyly, to a Rust UTF-8 String using +/// [`StringM::to_utf8_string_lossy`]. +/// +/// Convertible to/from escaped printable-ASCII using +/// [`Display`]/[`ToString`]/[`FromStr`]. + #[cfg(feature = "alloc")] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr( @@ -1690,7 +1701,9 @@ impl core::fmt::Display for StringM { let v = &self.0; #[cfg(not(feature = "alloc"))] let v = self.0; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } Ok(()) } } @@ -1702,7 +1715,9 @@ impl core::fmt::Debug for StringM { #[cfg(not(feature = "alloc"))] let v = self.0; write!(f, "StringM(")?; - write_utf8_lossy(f, v)?; + for b in escape_bytes::Escape::new(v) { + write!(f, "{}", b as char)?; + } write!(f, ")")?; Ok(()) } @@ -1712,7 +1727,8 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - s.try_into() + let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + Ok(Self(b)) } } @@ -1760,24 +1776,24 @@ impl StringM { impl StringM { #[cfg(feature = "alloc")] - pub fn to_string(&self) -> Result { + pub fn to_utf8_string(&self) -> Result { self.try_into() } #[cfg(feature = "alloc")] - pub fn into_string(self) -> Result { + pub fn into_utf8_string(self) -> Result { self.try_into() } #[cfg(feature = "alloc")] #[must_use] - pub fn to_string_lossy(&self) -> String { + pub fn to_utf8_string_lossy(&self) -> String { String::from_utf8_lossy(&self.0).into_owned() } #[cfg(feature = "alloc")] #[must_use] - pub fn into_string_lossy(self) -> String { + pub fn into_utf8_string_lossy(self) -> String { String::from_utf8_lossy(&self.0).into_owned() } } From 4b9135a6f0b7bb4889063a50ff37216ea79b8351 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:21:50 -0800 Subject: [PATCH 2/3] fix --- lib/xdrgen/generators/rust/src/types.rs | 2 +- spec/output/generator_spec_rust/block_comments.x/MyXDR.rs | 2 +- spec/output/generator_spec_rust/const.x/MyXDR.rs | 2 +- spec/output/generator_spec_rust/enum.x/MyXDR.rs | 2 +- spec/output/generator_spec_rust/nesting.x/MyXDR.rs | 2 +- spec/output/generator_spec_rust/optional.x/MyXDR.rs | 2 +- spec/output/generator_spec_rust/struct.x/MyXDR.rs | 2 +- spec/output/generator_spec_rust/test.x/MyXDR.rs | 2 +- spec/output/generator_spec_rust/union.x/MyXDR.rs | 2 +- .../block_comments.x/MyXDR.rs | 2 +- .../generator_spec_rust_custom_str_impls/const.x/MyXDR.rs | 2 +- .../output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs | 2 +- .../generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs | 2 +- .../generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs | 2 +- .../generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs | 2 +- .../output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs | 2 +- .../generator_spec_rust_custom_str_impls/union.x/MyXDR.rs | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/xdrgen/generators/rust/src/types.rs b/lib/xdrgen/generators/rust/src/types.rs index 9b332d3e3..80b982b42 100644 --- a/lib/xdrgen/generators/rust/src/types.rs +++ b/lib/xdrgen/generators/rust/src/types.rs @@ -1717,7 +1717,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs b/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs index 323dc5e5d..02a0ace9d 100644 --- a/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust/const.x/MyXDR.rs b/spec/output/generator_spec_rust/const.x/MyXDR.rs index b04843d2b..f77f20969 100644 --- a/spec/output/generator_spec_rust/const.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/const.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust/enum.x/MyXDR.rs b/spec/output/generator_spec_rust/enum.x/MyXDR.rs index d4b1468c8..74f81efe0 100644 --- a/spec/output/generator_spec_rust/enum.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/enum.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust/nesting.x/MyXDR.rs b/spec/output/generator_spec_rust/nesting.x/MyXDR.rs index aee6c525b..f19410082 100644 --- a/spec/output/generator_spec_rust/nesting.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/nesting.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust/optional.x/MyXDR.rs b/spec/output/generator_spec_rust/optional.x/MyXDR.rs index 4f95cb855..6fc6ff656 100644 --- a/spec/output/generator_spec_rust/optional.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/optional.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust/struct.x/MyXDR.rs b/spec/output/generator_spec_rust/struct.x/MyXDR.rs index aa7c9978b..7597450b9 100644 --- a/spec/output/generator_spec_rust/struct.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/struct.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust/test.x/MyXDR.rs b/spec/output/generator_spec_rust/test.x/MyXDR.rs index ba624636e..75e5c2baa 100644 --- a/spec/output/generator_spec_rust/test.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/test.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust/union.x/MyXDR.rs b/spec/output/generator_spec_rust/union.x/MyXDR.rs index b270e45c4..048e3cb5c 100644 --- a/spec/output/generator_spec_rust/union.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/union.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs index 323dc5e5d..02a0ace9d 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs index b04843d2b..f77f20969 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs index dadc93f9c..41b1f0378 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs index b31762e6a..703f68471 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs index 2ea5d39a3..178434f2a 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs index e37dc6a20..475a18c82 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs index de6cc45a0..71bcab60a 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } diff --git a/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs index 6175dbdf5..a012a4c8b 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs @@ -1727,7 +1727,7 @@ impl core::fmt::Debug for StringM { impl core::str::FromStr for StringM { type Err = Error; fn from_str(s: &str) -> core::result::Result { - let b = escape_bytes::unescape(&mut code, s.as_bytes()).map_err(|_| Error::Invalid)?; + let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?; Ok(Self(b)) } } From 193ddc25bdcde71b860b17828dc3fb1e5655b27e Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:26:04 -0800 Subject: [PATCH 3/3] remove unused code --- lib/xdrgen/generators/rust/src/types.rs | 25 ------------------- .../block_comments.x/MyXDR.rs | 25 ------------------- .../generator_spec_rust/const.x/MyXDR.rs | 25 ------------------- .../generator_spec_rust/enum.x/MyXDR.rs | 25 ------------------- .../generator_spec_rust/nesting.x/MyXDR.rs | 25 ------------------- .../generator_spec_rust/optional.x/MyXDR.rs | 25 ------------------- .../generator_spec_rust/struct.x/MyXDR.rs | 25 ------------------- .../generator_spec_rust/test.x/MyXDR.rs | 25 ------------------- .../generator_spec_rust/union.x/MyXDR.rs | 25 ------------------- .../block_comments.x/MyXDR.rs | 25 ------------------- .../const.x/MyXDR.rs | 25 ------------------- .../enum.x/MyXDR.rs | 25 ------------------- .../nesting.x/MyXDR.rs | 25 ------------------- .../optional.x/MyXDR.rs | 25 ------------------- .../struct.x/MyXDR.rs | 25 ------------------- .../test.x/MyXDR.rs | 25 ------------------- .../union.x/MyXDR.rs | 25 ------------------- 17 files changed, 425 deletions(-) diff --git a/lib/xdrgen/generators/rust/src/types.rs b/lib/xdrgen/generators/rust/src/types.rs index 80b982b42..bc05694ad 100644 --- a/lib/xdrgen/generators/rust/src/types.rs +++ b/lib/xdrgen/generators/rust/src/types.rs @@ -1660,31 +1660,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs b/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs index 02a0ace9d..b57d1e1a9 100644 --- a/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust/const.x/MyXDR.rs b/spec/output/generator_spec_rust/const.x/MyXDR.rs index f77f20969..b22bc802d 100644 --- a/spec/output/generator_spec_rust/const.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/const.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust/enum.x/MyXDR.rs b/spec/output/generator_spec_rust/enum.x/MyXDR.rs index 74f81efe0..e4c39a9c5 100644 --- a/spec/output/generator_spec_rust/enum.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/enum.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust/nesting.x/MyXDR.rs b/spec/output/generator_spec_rust/nesting.x/MyXDR.rs index f19410082..8f2a743b8 100644 --- a/spec/output/generator_spec_rust/nesting.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/nesting.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust/optional.x/MyXDR.rs b/spec/output/generator_spec_rust/optional.x/MyXDR.rs index 6fc6ff656..449173636 100644 --- a/spec/output/generator_spec_rust/optional.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/optional.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust/struct.x/MyXDR.rs b/spec/output/generator_spec_rust/struct.x/MyXDR.rs index 7597450b9..379e90626 100644 --- a/spec/output/generator_spec_rust/struct.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/struct.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust/test.x/MyXDR.rs b/spec/output/generator_spec_rust/test.x/MyXDR.rs index 75e5c2baa..df1ea45d9 100644 --- a/spec/output/generator_spec_rust/test.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/test.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust/union.x/MyXDR.rs b/spec/output/generator_spec_rust/union.x/MyXDR.rs index 048e3cb5c..4f65bba4c 100644 --- a/spec/output/generator_spec_rust/union.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/union.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs index 02a0ace9d..b57d1e1a9 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs index f77f20969..b22bc802d 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs index 41b1f0378..aa1a80b67 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs index 703f68471..3fbc3d03a 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs index 178434f2a..c2b46bc18 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs index 475a18c82..7011fe057 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs index 71bcab60a..002cbfa9e 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs index a012a4c8b..47f19c50f 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs @@ -1670,31 +1670,6 @@ pub struct StringM(Vec); #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); -/// `write_utf8_lossy` is a modified copy of the Rust stdlib docs examples here: -/// -fn write_utf8_lossy(f: &mut impl core::fmt::Write, mut input: &[u8]) -> core::fmt::Result { - loop { - match core::str::from_utf8(input) { - Ok(valid) => { - write!(f, "{valid}")?; - break; - } - Err(error) => { - let (valid, after_valid) = input.split_at(error.valid_up_to()); - write!(f, "{}", core::str::from_utf8(valid).unwrap())?; - write!(f, "\u{FFFD}")?; - - if let Some(invalid_sequence_length) = error.error_len() { - input = &after_valid[invalid_sequence_length..]; - } else { - break; - } - } - } - } - Ok(()) -} - impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")]