diff --git a/rinja/src/helpers.rs b/rinja/src/helpers.rs index 812c9ed90..8ed3ccdc7 100644 --- a/rinja/src/helpers.rs +++ b/rinja/src/helpers.rs @@ -132,6 +132,27 @@ crate::impl_for_ref! { } } +/// Implement [`PrimitiveType`] for [`Cell`] +/// +/// ``` +/// # use std::cell::Cell; +/// # use rinja::Template; +/// #[derive(Template)] +/// #[template(ext = "txt", source = "{{ value as u16 }}")] +/// struct Test<'a> { +/// value: &'a Cell +/// } +/// +/// assert_eq!(Test { value: &Cell::new(-1) }.to_string(), "65535"); +/// ``` +impl PrimitiveType for Cell { + type Value = T::Value; + + fn get(&self) -> Self::Value { + self.get().get() + } +} + /// An empty element, so nothing will be written. #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] pub struct Empty;