INNER CODE UNIT · Rust

new

spacejam/sled · src/lib.rs:278

    fn new(from: u64) -> Option<ObjectId> {
        NonZero::new(from).map(ObjectId)
    }
}

impl std::ops::Deref for ObjectId {
    type Target = u64;

    fn deref(&self) -> &u64 {
        let self_ref: &NonZero<u64> = &self.0;

        // NonZeroU64 is repr(transparent) where it wraps a u64
        // so it is guaranteed to match the binary layout. This
        // makes it safe to cast a reference to one as a reference
        // to the other like this.
        let self_ptr: *const NonZero<u64> = self_ref as *const _;
        let reference: *const u64 = self_ptr as *const u64;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…