Merge pull request #270 from Kijewski/pr-saturating

`std::num::Saturating` is stable since rust 1.74
This commit is contained in:
Guillaume Gomez 2024-11-24 21:11:56 +01:00 committed by GitHub
commit 067fd379b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -153,18 +153,18 @@ where
/// ///
/// ``` /// ```
/// # use std::cell::Cell; /// # use std::cell::Cell;
/// # use std::num::NonZeroI16; /// # use std::num::{NonZeroI16, Saturating};
/// # use std::rc::Rc; /// # use std::rc::Rc;
/// # use std::pin::Pin; /// # use std::pin::Pin;
/// # use rinja::Template; /// # use rinja::Template;
/// #[derive(Template)] /// #[derive(Template)]
/// #[template(ext = "txt", source = "{{ value as u16 }}")] /// #[template(ext = "txt", source = "{{ value as u16 }}")]
/// struct Test<'a> { /// struct Test<'a> {
/// value: &'a Pin<Rc<Cell<NonZeroI16>>> /// value: &'a Pin<Rc<Cell<Saturating<NonZeroI16>>>>
/// } /// }
/// ///
/// assert_eq!( /// assert_eq!(
/// Test { value: &Rc::pin(Cell::new(NonZeroI16::new(-1).unwrap())) }.to_string(), /// Test { value: &Rc::pin(Cell::new(Saturating(NonZeroI16::new(-1).unwrap()))) }.to_string(),
/// "65535", /// "65535",
/// ); /// );
/// ``` /// ```
@ -186,6 +186,15 @@ impl<T: PrimitiveType> PrimitiveType for std::num::Wrapping<T> {
} }
} }
impl<T: PrimitiveType> PrimitiveType for std::num::Saturating<T> {
type Value = T::Value;
#[inline]
fn get(&self) -> Self::Value {
self.0.get()
}
}
macro_rules! primitize_nz { macro_rules! primitize_nz {
($($nz:ty => $bare:ident,)+) => { $( ($($nz:ty => $bare:ident,)+) => { $(
impl PrimitiveType for $nz { impl PrimitiveType for $nz {