Unnamed repository; edit this file 'description' to name the repository.
Add more trait impls
| -rw-r--r-- | lib/smol_str/src/lib.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/smol_str/src/lib.rs b/lib/smol_str/src/lib.rs index 9845e4da05..73e757bcad 100644 --- a/lib/smol_str/src/lib.rs +++ b/lib/smol_str/src/lib.rs @@ -1,4 +1,4 @@ -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] extern crate alloc; @@ -319,6 +319,29 @@ impl AsRef<str> for SmolStr { } } +impl AsRef<[u8]> for SmolStr { + #[inline(always)] + fn as_ref(&self) -> &[u8] { + self.as_str().as_bytes() + } +} + +#[cfg(feature = "std")] +impl AsRef<std::ffi::OsStr> for SmolStr { + #[inline(always)] + fn as_ref(&self) -> &std::ffi::OsStr { + AsRef::<std::ffi::OsStr>::as_ref(self.as_str()) + } +} + +#[cfg(feature = "std")] +impl AsRef<std::path::Path> for SmolStr { + #[inline(always)] + fn as_ref(&self) -> &std::path::Path { + AsRef::<std::path::Path>::as_ref(self.as_str()) + } +} + impl From<&str> for SmolStr { #[inline] fn from(s: &str) -> SmolStr { |