Skip to main content

Index

Struct Index 

Source
pub struct Index<'a> { /* private fields */ }
Expand description

What is in a file, without what it says.

Borrows the source bytes and stores four parallel columns plus a table of distinct type names. At roughly 24 bytes per entity this is two orders of magnitude smaller than the decoded Model.

Use Index::entity to decode one record, or Index::materialize_closure to build a real Model from a chosen subset.

Implementations§

Source§

impl<'a> Index<'a>

Source

pub fn scan(source: &'a [u8]) -> Self

Scans source for record boundaries. Does not decode attributes.

Source

pub fn len(&self) -> usize

Number of records found.

Source

pub fn is_empty(&self) -> bool

Whether the file has no data records.

Source

pub fn ids(&self) -> impl Iterator<Item = EntityId> + '_

Every id, in file order.

Source

pub fn type_of(&self, id: EntityId) -> Option<&str>

Upper-cased type name of id, without decoding it.

Source

pub fn count_by_type(&self) -> BTreeMap<&str, usize>

How many records of each type. The census a viewer opens with.

Source

pub fn ids_of_type(&self, name: &str) -> Vec<EntityId>

Ids of every record whose type matches name, case-insensitively.

Source

pub fn entity(&self, id: EntityId) -> Option<Entity>

Decodes one record into an Entity.

The record is wrapped in a minimal synthetic file and handed to the real parser, so a lazily decoded entity cannot drift from its eager counterpart: there is only one decoder.

Source

pub fn materialize(&self, wanted: &[EntityId]) -> Model

Builds a Model from exactly wanted, and nothing else.

§Dangling references

The result is a real Model but not a self-contained one: an entity that referenced #7 still says Ref(7) even when #7 was not requested. Traversal will not resolve it. Use Index::materialize_closure unless you specifically want the raw subset and will handle missing targets yourself.

Source

pub fn materialize_closure(&self, wanted: &[EntityId]) -> Model

Builds a Model containing wanted and everything they reach.

Follows references transitively, so the result has no dangling Ref. This is the constructor to reach for: it is what makes a subset independently usable.

Auto Trait Implementations§

§

impl<'a> Freeze for Index<'a>

§

impl<'a> RefUnwindSafe for Index<'a>

§

impl<'a> Send for Index<'a>

§

impl<'a> Sync for Index<'a>

§

impl<'a> Unpin for Index<'a>

§

impl<'a> UnsafeUnpin for Index<'a>

§

impl<'a> UnwindSafe for Index<'a>

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<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> 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, 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.