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] 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() } }