Skip to main content

Table

Struct Table 

Source
pub struct Table {
    pub record_type: RecordType,
    pub free_list_head: u32,
    pub slots: Vec<Slot>,
    pub indexes: TableIndexes,
    /* private fields */
}

Fields§

§record_type: RecordType§free_list_head: u32

Head of the table’s free list: a link to the highest free slot, or 0 when every slot holds a record.

A link is (28 + 4 * slot) | 1 — the offset of that slot’s entry in the slot array, with the low bit set to tell it from a record offset. The slot it points at holds a link to the next free slot down, and the lowest one holds 0. That is why a fresh, empty table carries 0x1d: one slot, free, at 28 + 0.

§slots: Vec<Slot>

Record slots in file order. A slot’s index is the record number it holds.

§indexes: TableIndexes

The table’s index region.

Implementations§

Source§

impl Table

Source

pub fn records(&self) -> impl Iterator<Item = &Record>

Live records, skipping free and empty slots.

Source

pub fn records_mut(&mut self) -> impl Iterator<Item = &mut Record>

Source

pub fn record_count(&self) -> usize

Source

pub fn next_record_number(&self) -> u32

Lowest unused record number. macOS numbers records from 0 upward.

Source

pub fn insert(&mut self, record: Record) -> u32

Store a record, taking the head of the free list when there is one.

The record’s number is the slot it lands in — that is what a record number is here — so it is assigned rather than taken from the caller, and returned. The record’s bytes go at the end of the records region, the way macOS appends them, however low the reused slot number is.

Source

pub fn delete(&mut self, number: u32) -> bool

Delete a record, freeing its slot the way macOS frees one.

The slot keeps its place unless it is the last one, in which case the array loses exactly that entry — trailing free slots below it are left alone, and the array never shrinks below one slot. Surviving records keep their numbers: index entries refer to records by number, and macOS never renumbers.

Returns whether a record was there to delete.

Source

pub fn unique_index_attribute_ids(&self) -> Option<&[u32]>

The attributes of the table’s unique index, by id.

None when this build could not parse the index region, or the table declares no unique index.

Source

pub fn has_record_with_unique_key( &self, relation: &Relation, attributes: &[Option<Value>], ) -> bool

True when a record already has the same key as attributes under the table’s unique index.

The unique index is the one the region marks kind == 1; the attributes it names are the relation’s notion of identity, which is what macOS refuses a duplicate of. A table whose index region this build could not parse answers false: it cannot tell, and refusing a write macOS would accept is worse than allowing it.

Source

pub fn rebuild_indexes(&mut self, relation: &Relation) -> Result<()>

Rebuild every index from the table’s records.

Rebuilding rather than patching keeps the indexes consistent with the records by construction; tests/keychain_index.rs checks that a rebuild reproduces the entries and the ordering macOS wrote.

Trait Implementations§

Source§

impl Clone for Table

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Table

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Table

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnsafeUnpin for Table

§

impl UnwindSafe for Table

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V