Skip to content

Commit 593d89f

Browse files
committed
Add more trait impls
1 parent eb00f33 commit 593d89f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/lib.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![no_std]
1+
#![cfg_attr(not(feature = "std"), no_std)]
22
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
33

44
extern crate alloc;
@@ -319,6 +319,29 @@ impl AsRef<str> for SmolStr {
319319
}
320320
}
321321

322+
impl AsRef<[u8]> for SmolStr {
323+
#[inline(always)]
324+
fn as_ref(&self) -> &[u8] {
325+
self.as_str().as_bytes()
326+
}
327+
}
328+
329+
#[cfg(feature = "std")]
330+
impl AsRef<std::ffi::OsStr> for SmolStr {
331+
#[inline(always)]
332+
fn as_ref(&self) -> &std::ffi::OsStr {
333+
AsRef::<std::ffi::OsStr>::as_ref(self.as_str())
334+
}
335+
}
336+
337+
#[cfg(feature = "std")]
338+
impl AsRef<std::path::Path> for SmolStr {
339+
#[inline(always)]
340+
fn as_ref(&self) -> &std::path::Path {
341+
AsRef::<std::path::Path>::as_ref(self.as_str())
342+
}
343+
}
344+
322345
impl From<&str> for SmolStr {
323346
#[inline]
324347
fn from(s: &str) -> SmolStr {

0 commit comments

Comments
 (0)