Skip to content

Commit

Permalink
Add more trait impls
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Sep 3, 2024
1 parent eb00f33 commit 593d89f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![no_std]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

extern crate alloc;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 593d89f

Please sign in to comment.