diff --git a/src/string.rs b/src/string.rs index cb7c298..e0ae7aa 100644 --- a/src/string.rs +++ b/src/string.rs @@ -7,6 +7,10 @@ use core::fmt::{self, Debug, Display, Formatter, Write}; use core::hash::{Hash, Hasher}; use core::ops::{Add, AddAssign, Deref}; use core::str::FromStr; +#[cfg(feature = "std")] +use std::ffi::OsStr; +#[cfg(feature = "std")] +use std::path::Path; #[cfg(not(feature = "std"))] use alloc::string::String; @@ -432,6 +436,29 @@ impl Borrow for EcoString { } } +impl AsRef<[u8]> for EcoString { + #[inline] + fn as_ref(&self) -> &[u8] { + self.as_str().as_bytes() + } +} + +#[cfg(feature = "std")] +impl AsRef for EcoString { + #[inline] + fn as_ref(&self) -> &OsStr { + self.as_str().as_ref() + } +} + +#[cfg(feature = "std")] +impl AsRef for EcoString { + #[inline] + fn as_ref(&self) -> &Path { + self.as_str().as_ref() + } +} + impl From for EcoString { #[inline] fn from(c: char) -> Self {