plane_2d/
immutable.rs

1#[cfg(feature = "bevy_reflect")]
2use bevy_reflect::Reflect;
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5use std::ops::Deref;
6
7/// Helper struct that insures that inner value can't be mutated even if user has mutable access to it.
8#[repr(transparent)]
9#[derive(Debug, Default, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
12pub struct Immutable<T>(T);
13
14impl<T> Immutable<T> {
15    #[inline]
16    pub fn new(value: T) -> Self {
17        Self(value)
18    }
19
20    #[inline]
21    pub fn get(&self) -> &T {
22        &self.0
23    }
24}
25
26impl<T> Deref for Immutable<T> {
27    type Target = T;
28
29    #[inline]
30    fn deref(&self) -> &Self::Target {
31        self.get()
32    }
33}