generic_std/
rc.rs

1//! Single-threaded reference-counting pointers.
2
3use crate::{plug::PlugType, Rcb, WeakRcb};
4use std::rc::{Rc, Weak};
5
6/// HKT `std::rc::Rc<T>` with a type slot.
7pub struct H1Rc;
8
9impl<T> PlugType<T> for H1Rc {
10    type T = Rc<T>;
11}
12
13/// HKT `std::rc::Weak<T>` with a type slot.
14pub struct H1Weak;
15
16impl<T> PlugType<T> for H1Weak {
17    type T = Weak<T>;
18}
19
20impl<T> Rcb<T> for Rc<T> {
21    type Weak = Weak<T>;
22
23    fn new(x: T) -> Self {
24        Rc::<T>::new(x)
25    }
26
27    fn try_unwrap(this: Self) -> Result<T, Self> {
28        Rc::<T>::try_unwrap(this)
29    }
30
31    fn downgrade(this: &Self) -> Self::Weak {
32        Rc::<T>::downgrade(this)
33    }
34}
35
36impl<T> WeakRcb<T> for Weak<T> {
37    type Strong = Rc<T>;
38
39    fn upgrade(&self) -> Option<Self::Strong> {
40        Weak::<T>::upgrade(self)
41    }
42}