From b57acb392d55923e181255f1cbfb63410019fe91 Mon Sep 17 00:00:00 2001 From: Luiz Carvalho Date: Fri, 23 Sep 2022 00:54:08 -0300 Subject: [PATCH] feat: impl `AsRef` There are a few cases in `std` where functions expect a `T: AsRef`, mainly when working with OS related operations like passings args to a `Command`. --- src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8c92e51..6712dfc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] extern crate alloc; use alloc::{ @@ -310,6 +310,13 @@ impl Borrow for SmolStr { } } +#[cfg(feature = "std")] +impl AsRef for SmolStr { + fn as_ref(&self) -> &std::ffi::OsStr { + (&**self).as_ref() + } +} + impl FromStr for SmolStr { type Err = Infallible;