Skip to main content

calimero_sys/types/
ref.rs

1use std::marker::PhantomData;
2use std::ptr;
3
4use crate::PtrSizedInt;
5
6/// Abstraction type that encodes the pointer to any aggregate type T
7#[repr(C)]
8#[derive(Debug)]
9pub struct Ref<T> {
10    ptr: PtrSizedInt,
11    phantom: PhantomData<T>,
12}
13
14impl<T> Ref<T> {
15    pub fn new(val: &T) -> Self {
16        Ref {
17            ptr: PtrSizedInt::new(ptr::from_ref(val).addr()),
18            phantom: PhantomData,
19        }
20    }
21}
22
23impl<T> From<T> for Ref<T> {
24    fn from(value: T) -> Self {
25        Ref::new(&value)
26    }
27}