object_safe/
obj.rs

1use core::ops::{Deref, DerefMut};
2
3/// Convenient wrapper struct that implements any of the traits supported by
4/// this crate if the contained type derefs to something implementing the
5/// `**Obj` analog trait.
6#[derive(Clone, Copy, Debug)]
7pub struct Obj<T>(pub T);
8
9impl<T> Obj<T> {
10    /// Typically, you should just use Obj(item). This method is for
11    /// compatibility with type aliases.
12    pub fn new(item: T) -> Self {
13        Obj(item)
14    }
15}
16
17impl<T> Deref for Obj<T> {
18    type Target = T;
19
20    fn deref(&self) -> &Self::Target {
21        &self.0
22    }
23}
24
25impl<T> DerefMut for Obj<T> {
26    fn deref_mut(&mut self) -> &mut Self::Target {
27        &mut self.0
28    }
29}