react/use_ref/
into_ref_value.rs1use std::rc::Rc;
2
3use convert_js::WrapJsCast;
4use wasm_bindgen::JsCast;
5
6pub trait IntoRefValue<T> {
7 fn into_ref_value(self) -> T;
8}
9
10impl<T> IntoRefValue<T> for T {
11 #[inline]
12 fn into_ref_value(self) -> T {
13 self
14 }
15}
16
17impl<T> IntoRefValue<Rc<T>> for T {
18 #[inline]
19 fn into_ref_value(self) -> Rc<T> {
20 Rc::new(self)
21 }
22}
23
24impl<T: JsCast> IntoRefValue<WrapJsCast<T>> for T {
25 #[inline]
26 fn into_ref_value(self) -> WrapJsCast<T> {
27 WrapJsCast(self)
28 }
29}
30
31impl<T: JsCast> IntoRefValue<T> for WrapJsCast<T> {
32 #[inline]
33 fn into_ref_value(self) -> T {
34 self.0
35 }
36}
37
38impl<T> IntoRefValue<Box<T>> for T {
39 #[inline]
40 fn into_ref_value(self) -> Box<T> {
41 Box::new(self)
42 }
43}
44
45impl<T> IntoRefValue<T> for Box<T> {
46 #[inline]
47 fn into_ref_value(self) -> T {
48 *self
49 }
50}