diff --git a/rinja/src/helpers.rs b/rinja/src/helpers.rs index 4b8a6028..bf345599 100644 --- a/rinja/src/helpers.rs +++ b/rinja/src/helpers.rs @@ -153,18 +153,18 @@ where /// /// ``` /// # use std::cell::Cell; -/// # use std::num::NonZeroI16; +/// # use std::num::{NonZeroI16, Saturating}; /// # use std::rc::Rc; /// # use std::pin::Pin; /// # use rinja::Template; /// #[derive(Template)] /// #[template(ext = "txt", source = "{{ value as u16 }}")] /// struct Test<'a> { -/// value: &'a Pin>> +/// value: &'a Pin>>> /// } /// /// 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", /// ); /// ``` @@ -186,6 +186,15 @@ impl PrimitiveType for std::num::Wrapping { } } +impl PrimitiveType for std::num::Saturating { + type Value = T::Value; + + #[inline] + fn get(&self) -> Self::Value { + self.0.get() + } +} + macro_rules! primitize_nz { ($($nz:ty => $bare:ident,)+) => { $( impl PrimitiveType for $nz {