diff --git a/src/lib.rs b/src/lib.rs index bc9aa04..b6778e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,7 @@ impl fmt::Display for StrBufError { } } +#[derive(Copy, Clone)] ///Stack based string. /// ///It's size is `mem::size_of::() + mem::size_of::()`, but remember that it can be padded. @@ -376,27 +377,6 @@ impl core::fmt::Debug for StrBuf { } } -impl Clone for StrBuf { - #[inline] - fn clone(&self) -> Self { - let mut result = Self::new(); - unsafe { - result.push_str_unchecked(self.as_str()) - } - result - } - - #[inline] - fn clone_from(&mut self, source: &Self) { - self.clear(); - unsafe { - self.push_str_unchecked(source.as_str()); - } - } -} - -impl Copy for StrBuf {} - impl AsRef<[u8]> for StrBuf { #[inline(always)] fn as_ref(&self) -> &[u8] { @@ -483,3 +463,12 @@ impl core::convert::TryFrom<&str> for StrBuf { Self::from_str_checked(text) } } + +impl core::str::FromStr for StrBuf { + type Err = StrBufError; + + #[inline(always)] + fn from_str(text: &str) -> Result { + Self::from_str_checked(text) + } +} diff --git a/tests/push.rs b/tests/push.rs index f175cee..6e6bcc5 100644 --- a/tests/push.rs +++ b/tests/push.rs @@ -13,4 +13,7 @@ fn should_correctly_truncate_by_char_boundary() { assert_eq!(buf.push_str("i"), 1); assert_eq!(buf, "ロri"); assert_eq!(buf.push_str("."), 0); + + let copy = buf; + assert_eq!(copy, buf); }