9 releases

0.3.2 Jun 27, 2022
0.3.1 Apr 5, 2022
0.2.3 Apr 1, 2022
0.2.2 Mar 31, 2022
0.1.1 Mar 28, 2022

#99 in Rust patterns

Download history 35307/week @ 2023-12-08 33000/week @ 2023-12-15 19200/week @ 2023-12-22 22404/week @ 2023-12-29 34112/week @ 2024-01-05 40868/week @ 2024-01-12 44096/week @ 2024-01-19 44063/week @ 2024-01-26 47541/week @ 2024-02-02 41613/week @ 2024-02-09 47092/week @ 2024-02-16 49398/week @ 2024-02-23 49911/week @ 2024-03-01 49231/week @ 2024-03-08 53411/week @ 2024-03-15 41741/week @ 2024-03-22

202,805 downloads per month
Used in 230 crates (26 directly)

MIT/Apache

58KB
521 lines

sptr: The Strict Provenance Polyfill

crates.io Rust CI

This library provides a stable polyfill for Rust's [Strict Provenance] experiment.

Mapping to STD APIs:

This crate "overlays" a bunch of unstable std apis, here are the mappings:

core::ptr (sptr)

core::pointer (sptr::Strict)

  • pub fn addr(self) -> usize;
  • pub fn expose_addr(self) -> usize;
  • pub fn with_addr(self, addr: usize) -> Self;
  • pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self;

NON-STANDARD EXTENSIONS (disabled by default, use at your own risk)

  • sptr::uptr (feature = uptr)
  • sptr::iptr (feature = uptr)
  • sptr::OpaqueFnPtr (feature = opaque_fn)

Applying The Overlay

Swapping between sptr and core::ptr should be as simple as switching between sptr:: and ptr:: for static functions. For methods, you must import sptr::Strict into your module for the extension trait's methods to overlay std. The compiler will (understandably) complain that you are overlaying std, so you will need to also silence that as seen in the following example:

#![allow(unstable_name_collisions)]
use sptr::Strict;

let ptr = sptr::invalid_mut::<u8>(1);
println!("{}", ptr.addr());

By default, this crate will also mark methods on pointers as "deprecated" if they are incompatible with strict_provenance. If you don't want this, set default-features = false in your Cargo.toml.

Rust is the canonical source of definitions for these APIs and semantics, but the docs here will vaguely try to mirror the docs checked into Rust.

No runtime deps

Features