diff --git a/rust/src/embedded.rs b/rust/src/embedded.rs index e084d75..e350382 100644 --- a/rust/src/embedded.rs +++ b/rust/src/embedded.rs @@ -472,10 +472,14 @@ impl { fn strict_encode(&self, writer: W) -> io::Result { + debug_assert_ne!( + MIN_LEN, 0, + "Restricted string type can't have minimum length equal to zero" + ); let sizing = Sizing::new(MIN_LEN as u64, MAX_LEN as u64); unsafe { writer - .register_list(&C::strict_dumb(), sizing) + .register_rstring(&C::strict_dumb(), &C1::strict_dumb(), sizing) .write_string::(self.as_bytes()) } } diff --git a/rust/src/ident.rs b/rust/src/ident.rs index c392699..e919695 100644 --- a/rust/src/ident.rs +++ b/rust/src/ident.rs @@ -19,7 +19,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::fmt::{self, Debug, Formatter}; use std::str::FromStr; use amplify::Wrapper; @@ -46,14 +45,18 @@ macro_rules! impl_ident_type { fn try_from(s: String) -> Result { Self::from_str(&s) } } - impl Debug for $ty { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + impl ::core::fmt::Debug for $ty { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { f.debug_tuple(&$crate::type_name::()) .field(&self.as_str()) .finish() } } + impl ::core::borrow::Borrow for $ty { + fn borrow(&self) -> &str { self.as_str() } + } + impl $ty { /// Returns string reference. pub fn as_str(&self) -> &str { self.0.as_str() } diff --git a/rust/src/stl.rs b/rust/src/stl.rs index 70d164d..5603858 100644 --- a/rust/src/stl.rs +++ b/rust/src/stl.rs @@ -21,6 +21,7 @@ #![allow(non_camel_case_types, unused_imports)] +use std::borrow::Borrow; use std::fmt::{Debug, Display, Formatter}; use std::marker::PhantomData; use std::ops::Deref; @@ -74,7 +75,7 @@ pub trait RestrictedCharSet: pub struct RString< C1: RestrictedCharSet, C: RestrictedCharSet = C1, - const MIN: usize = 0, + const MIN: usize = 1, const MAX: usize = 255, > { s: Confined, @@ -102,6 +103,12 @@ impl &str { self.s.as_str() } } +impl Borrow + for RString +{ + fn borrow(&self) -> &str { self.s.as_str() } +} + impl FromStr for RString { diff --git a/rust/src/traits.rs b/rust/src/traits.rs index c09f1dc..7994aee 100644 --- a/rust/src/traits.rs +++ b/rust/src/traits.rs @@ -97,11 +97,20 @@ pub trait TypedWrite: Sized { #[doc(hidden)] unsafe fn register_unicode(self, sizing: Sizing) -> Self { self } #[doc(hidden)] - #[deprecated(since = "2.3.1", note = "use register_list with AsciiSym type")] + #[deprecated(since = "2.3.1", note = "use register_rstring")] unsafe fn register_ascii(self, sizing: Sizing) -> Self { panic!("TypedWrite::register_ascii must not be called; pls see compilation warnings") } #[doc(hidden)] + unsafe fn register_rstring( + self, + c: &impl StrictEncode, + c1: &impl StrictEncode, + sizing: Sizing, + ) -> Self { + self + } + #[doc(hidden)] unsafe fn register_list(self, ty: &impl StrictEncode, sizing: Sizing) -> Self { self } #[doc(hidden)] unsafe fn register_set(self, ty: &impl StrictEncode, sizing: Sizing) -> Self { self }