Skip to content

Commit

Permalink
Implement PrimitiveType for Cell<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Oct 17, 2024
1 parent f7d1e9a commit 905c926
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions rinja/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ crate::impl_for_ref! {
}
}

/// Implement [`PrimitiveType`] for [`Cell<T>`]
///
/// ```
/// # use std::cell::Cell;
/// # use rinja::Template;
/// #[derive(Template)]
/// #[template(ext = "txt", source = "{{ value as u16 }}")]
/// struct Test<'a> {
/// value: &'a Cell<i16>
/// }
///
/// assert_eq!(Test { value: &Cell::new(-1) }.to_string(), "65535");
/// ```
impl<T: PrimitiveType + Copy> PrimitiveType for Cell<T> {
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;
Expand Down

0 comments on commit 905c926

Please sign in to comment.