pub unsafe trait Update {
// Required method
unsafe fn maybe_update(old_pointer: *mut Self, new_value: Self) -> bool;
}
Expand description
§Safety
Implementing this trait requires the implementor to verify:
maybe_update
ensures the properties it is intended to ensure.- If the value implements
Eq
, it is safe to compare an instance of the value from an older revision with one from the newer revision. If the value compares as equal, no update is needed to bring it into the newer revision.
NB: The second point implies that Update
cannot be implemented for any
&'db T
– (i.e., any Rust reference tied to the database).
Such a value could refer to memory that was freed in some
earlier revision. Even if the memory is still valid, it could also
have been part of a tracked struct whose values were mutated,
thus invalidating the 'db
lifetime (from a stacked borrows perspective).
Either way, the Eq
implementation would be invalid.
Required Methods§
Sourceunsafe fn maybe_update(old_pointer: *mut Self, new_value: Self) -> bool
unsafe fn maybe_update(old_pointer: *mut Self, new_value: Self) -> bool
§Returns
True if the value should be considered to have changed in the new revision.
§Safety
§Requires
Informally, requires that old_value
points to a value in the
database that is potentially from a previous revision and new_value
points to a value produced in this revision.
More formally, requires that
- all parameters meet the validity and safety invariants for their type
old_value
further points to allocated memory that meets the validity invariant forSelf
- all data owned by
old_value
further meets its safety invariant- not that borrowed data in
old_value
only meets its validity invariant and hence cannot be dereferenced; essentially, a&T
may point to memory in the database which has been modified or even freed in the newer revision.
- not that borrowed data in
§Ensures
That old_value
is updated with
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.