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    #[inline]
19    fn from(value: NonNull<Type>) -> Self {return Self {
20        to: Some(value)
21    }}
22}
23
24//> CONVERSIONS -> FROM OPTION NONNULL
25const impl<Type> From<Option<NonNull<Type>>> for Pointer<Type> {
26    #[inline]
27    fn from(value: Option<NonNull<Type>>) -> Self {return Self {
28        to: value
29    }}
30}
31
32//> CONVERSIONS -> FROM RAW
33const impl<Type> From<*mut Type> for Pointer<Type> {
34    #[inline]
35    fn from(value: *mut Type) -> Self {return Self {
36        to: NonNull::new(value)
37    }}
38}
39
40//> CONVERSIONS -> FROM REFERENCE
41const impl<Type> From<&mut Type> for Pointer<Type> {
42    #[inline]
43    fn from(value: &mut Type) -> Self {Self::from(value as *mut Type)}
44}