From 3719f81b35f1e442b7ff721864256cec475eecf3 Mon Sep 17 00:00:00 2001 From: Zack Date: Mon, 3 Apr 2023 21:38:03 -0700 Subject: [PATCH] Added CellView type to limit where Cell value can be set from. --- src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index e69de29..3a721ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -0,0 +1,15 @@ +#![no_std] + +use core::cell::Cell; + +/// Provides a view only reference to a [Cell]. +/// Useful alternative to `&Cell` when an API wants to control where a [Cell]s value can be set. +#[derive(Copy, Clone)] +pub struct CellView<'a, T: Copy>(&'a Cell); + +impl<'a, T: Copy> CellView<'a, T> { + #[inline] + pub fn get(self) -> T { + self.0.get() + } +}