Skip to content

Commit

Permalink
tostatic: fix build with nostd
Browse files Browse the repository at this point in the history
  • Loading branch information
chifflier committed Nov 19, 2024
1 parent 7c44087 commit e713ed5
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/tostatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ macro_rules! impl_tostatic_primitive {
impl_tostatic_primitive!(bool);
impl_tostatic_primitive!(I i8 i16 i32 i64 i128 isize);
impl_tostatic_primitive!(I u8 u16 u32 u64 u128 usize);
impl_tostatic_primitive!(I String);
impl_tostatic_primitive!(str => String, |s| s.to_string());

impl<T> ToStatic for &'_ T
where
Expand All @@ -63,17 +61,6 @@ where
}
}

impl<T> ToStatic for Box<T>
where
T: ToStatic,
{
type Owned = Box<T::Owned>;

fn to_static(&self) -> Self::Owned {
Box::new(self.as_ref().to_static())
}
}

impl<T> ToStatic for Option<T>
where
T: ToStatic,
Expand All @@ -84,3 +71,20 @@ where
self.as_ref().map(ToStatic::to_static)
}
}

#[cfg(feature = "std")]
const _: () = {
impl_tostatic_primitive!(I String);
impl_tostatic_primitive!(str => String, |s| s.to_string());

impl<T> ToStatic for Box<T>
where
T: ToStatic,
{
type Owned = Box<T::Owned>;

fn to_static(&self) -> Self::Owned {
Box::new(self.as_ref().to_static())
}
}
};

0 comments on commit e713ed5

Please sign in to comment.