2 unstable releases

0.2.0 Mar 6, 2023
0.1.0 Mar 6, 2023

#2865 in Rust patterns

Download history 36/week @ 2024-07-22 21/week @ 2024-07-29 22/week @ 2024-08-05 22/week @ 2024-08-12 18/week @ 2024-08-19 49/week @ 2024-08-26 21/week @ 2024-09-02 23/week @ 2024-09-09 22/week @ 2024-09-16 38/week @ 2024-09-23 18/week @ 2024-09-30 5/week @ 2024-10-07 30/week @ 2024-10-14 12/week @ 2024-10-21 10/week @ 2024-10-28 25/week @ 2024-11-04

77 downloads per month
Used in 7 crates (2 directly)

MIT/Apache

19KB
107 lines

ConstPtr

Rusts std::ptr::NonNull wraps a *mut pointer. Sometimes this has implications that are not desired. ConstPtr wraps NullPtr but removes the mutable and uninit API's. As consequence it can only be constructed to point to a valid object (although it may become dangling when the object becomes destroyed). This simplifies handling lifetime erased references because a &reference implicitly coerces to a *const pointer and adds some safety net as in one can't accidentally get a mutable reference to something that should been const.

'nostd' compatibility

By default the 'std' feature is enabled which pulls in dependencies on rusts stdlib. When one disables this in 'default' then ConstPtr becomes no-std compatible.

No runtime deps

Features