pub struct In<'a, T>(/* private fields */);Expand description
Uninitialized stable pointer to T.
Used for the initialize-in-place strategy employed by the View::build method.
Implementations§
Source§impl<'a, T> In<'a, T>
impl<'a, T> In<'a, T>
Sourcepub unsafe fn cast<U>(self) -> In<'a, U>
pub unsafe fn cast<U>(self) -> In<'a, U>
Cast this pointer from In<T> to In<U>.
§Safety
Caller needs to guarantee safety as per usual rules of pointer casting, namely:
TandUmust have the same size.TandUmust have the same memory layout.
Sourcepub fn in_place<F>(self, f: F) -> Out<'a, T>
pub fn in_place<F>(self, f: F) -> Out<'a, T>
Build this T in-place using a raw pointer
§Safety
This method itself is safe since just obtaining a raw pointer by itself is also safe,
it does however require unsafe code to construct Out<T> inside the closure f.
use kobold::internal::{In, Out};
use kobold::init;
struct Foo {
int: u32,
float: f64,
}
fn build_in(p: In<Foo>) -> Out<Foo> {
let out = p.in_place(|p| unsafe {
// Initialize fields of `Foo`
init!(p.int = 42);
init!(p.float = 3.14);
// Both fields have been initialized
Out::from_raw(p)
});
assert_eq!(out.int, 42);
assert_eq!(out.float, 3.14);
out
}Sourcepub unsafe fn raw<F>(raw: *mut T, f: F) -> Out<'a, T>
pub unsafe fn raw<F>(raw: *mut T, f: F) -> Out<'a, T>
Initialize raw pointer raw using a builder closure f.
§Safety
Caller must guarantee that raw is a stable pointer for the entire life of T.
If raw has already been initialized this can cause a memory leak, which is safe but undesirable.
Sourcepub fn pinned<F>(pin: Pin<&'a mut MaybeUninit<T>>, f: F) -> Out<'a, T>
pub fn pinned<F>(pin: Pin<&'a mut MaybeUninit<T>>, f: F) -> Out<'a, T>
Initialize a pinned uninitialized data using a builder closure f.
§Safety
This method is safe, it can however leak memory if pin has already been initialized.