bundle_sources/
immutable.rs1use std::ops::Deref;
6use std::fmt::{Display,Debug,Formatter,self};
7
8pub struct Immutable<T> (T);
9impl<T> Immutable<T> {
10 pub fn new(t : T) -> Immutable<T> { Immutable(t) }
11}
12impl<T> Deref for Immutable<T> {
13 type Target = T;
14 fn deref(&self) -> &T { &self.0 }
15}
16impl<T> From<T> for Immutable<T> {
17 fn from(t : T) -> Immutable<T> { Immutable(t) }
18}
19
20impl<T : Display> Display for Immutable<T> {
21 fn fmt(&self, fmt : &mut Formatter) -> Result<(),fmt::Error> {
22 self.0.fmt(fmt)
23 }
24}
25impl<T : Debug> Debug for Immutable<T> {
26 fn fmt(&self, fmt : &mut Formatter) -> Result<(),fmt::Error> {
27 self.0.fmt(fmt)
28 }
29}