pub struct LogNonNull<T: PSafe + ?Sized, A: MemPool> { /* private fields */ }
Expand description

An unsafe pointer with dereferencing and logging capability

This type is !PSafe and its constructor functions are unsafe. This is because of LogNonNull treating like a raw pointer. LogNonNull objects are useful for obtaining performance. PRefCell::as_non_null_mut() is an alternative to PRefCell::borrow_mut() which provides unsafe mutable access to the underlying data.

PNonNullMut is an alias name in the pool module for LogNonNullMut.

Safety

  • As in raw pointers, LogNonNull is Copy and is not bounded to a specific lifetime.
  • It does not follow the borrow mechanism and thus multiple mutable access is possible.

Examples

use corundum::default::*;
use corundum::ptr::LogNonNull;
 
type P = Allocator;
 
fn multiply(mut obj: LogNonNull<i32,P>, m: i32) {
    // Takes a log if required and then provides mut ref to the object
    *obj *= m;
}
 
let root = P::open::<PRefCell<i32>>("foo.pool", O_CF).unwrap();
 
P::transaction(|j| {
    let mut borrow = root.borrow_mut(j);
    *borrow = 5;
 
    multiply( unsafe { root.as_non_null_mut(j) }, 10 );
}).unwrap();
 
assert_eq!(*root.borrow(), 50);

Implementations

Creates a new LogNonNull.

Safety

ptr and logged must be non-null.

Creates a Some(LogNonNull) if ptr is not null; otherwise None.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.