Skip to main content

libutils_pointer/
conversions.rs

1//^
2//^ HEAD
3//^
4
5//> HEAD -> SUPER
6use super::Pointer;
7
8//> HEAD -> CORE
9use core::ptr::NonNull;
10
11
12//^
13//^ CONVERSIONS
14//^
15
16//> CONVERSIONS -> FROM NONNULL
17const impl<Type> From<NonNull<Type>> for Pointer<Type> {
18    fn from(value: NonNull<Type>) -> Self {return Self {
19        to: Some(value)
20    }}
21}
22
23//> CONVERSIONS -> FROM OPTION NONNULL
24const impl<Type> From<Option<NonNull<Type>>> for Pointer<Type> {
25    fn from(value: Option<NonNull<Type>>) -> Self {return Self {
26        to: value
27    }}
28}
29
30//> CONVERSIONS -> FROM RAW
31const impl<Type> From<*mut Type> for Pointer<Type> {
32    fn from(value: *mut Type) -> Self {return Self {
33        to: NonNull::new(value)
34    }}
35}
36
37//> CONVERSIONS -> FROM REFERENCE
38const impl<Type> From<&mut Type> for Pointer<Type> {
39    fn from(value: &mut Type) -> Self {Self::from(value as *mut Type)}
40}