Skip to main content

Index

Struct Index 

Source
pub struct Index {
    pub level: IndexLevel,
    pub records: Vec<IndexRecord>,
    pub child_counts: BTreeMap<PathBuf, usize>,
}
Expand description

A built (or being-built) catalog for one IndexLevel, with both rendered artifacts available. Pure data until written via Index::write_level.

Fields§

§level: IndexLevel

Which level this catalog is for.

§records: Vec<IndexRecord>

The complete record set for this level (type-folder level; empty for root/layer rollups, which carry only counts).

§child_counts: BTreeMap<PathBuf, usize>

Per-child counts for root/layer rollups (child path → file count).

Implementations§

Source§

impl Index

Source

pub fn build_type_folder(store: &Store, type_folder: &Path) -> Result<Index>

Build a type-folder catalog by aggregating across date-shards, producing both artifacts. index.md selection is recency (updated desc, ties by path asc; cap 500 with a ## More footer over the cap); index.jsonl holds every file. A file missing summary gets a placeholder + a validate-detectable issue (the index never invents summaries).

Source

pub fn build_layer(store: &Store, layer: Layer) -> Result<Index>

Build a layer catalog: every non-empty type-folder under the layer with (N) counts and a newest-file summary preview (≤ 80 chars), plus the loose records that live directly at the layer root (files with no type-folder between them and the layer). The type-folder rollup is the index.md; the loose records are the layer’s own index.jsonl (so structured reads — query, dedup, graph — see a loose file the same way they see a canonical one). A layer with no loose files carries no index.jsonl, so existing stores are byte-unchanged.

Source

pub fn build_root(store: &Store) -> Result<Index>

Build the store-wide root catalog: one heading per non-empty layer with total count + bulleted per-type sub-entries with (N) counts.

Source

pub fn to_markdown(&self) -> String

Render this catalog as a canonical index.md.

Source

pub fn to_jsonl(&self) -> String

Render this catalog’s records as the complete index.jsonl (one JSON object per file, stable key order so diffs stay minimal). Used at the type-folder level for its files, and at the layer level for the loose files that live directly at the layer root. The root rollup carries no records, so it never produces a jsonl.

Source§

impl Index

Source

pub fn on_write(store: &Store, file: &Path) -> Result<()>

Write-through (loop, O(changed)). Upsert a new/updated content file. Reads the affected type-folder’s index.jsonl (the sanctioned per-folder sidecar read — never a whole-store walk), applies the change, and atomically rewrites that folder’s index.md + index.jsonl plus the parent layer + root rollups so the artifacts equal a rebuild_all over the same end state.

Source

pub fn on_rename(store: &Store, old: &Path, new: &Path) -> Result<()>

Write-through (loop, O(changed)). Move a file’s entry between type-folder indexes (or within, if the same folder) in both index.md and index.jsonl, fixing counts on both sides.

Source

pub fn on_remove(store: &Store, file: &Path) -> Result<()>

Write-through (loop, O(changed)). Drop a file’s entry from both index.md and index.jsonl; decrement counts; if the browse view drops below the cap, the next-most-recent is already present in the complete jsonl record set and re-renders into the md automatically.

Source

pub fn rebuild_all(store: &Store) -> Result<()>

SWEEP repair. Walk the store once and atomically (re)write root + every non-empty layer + every non-empty type-folder index.md and index.jsonl (compacting the jsonl). Also runs Index::cleanup.

Source

pub fn rebuild_folder(store: &Store, folder: &Path) -> Result<()>

Rebuild ONE type-folder’s index.md/index.jsonl from a fresh walk, then cascade the new child count up to the layer and root rollups — so a scoped dbmd index rebuild --folder leaves the hierarchy consistent, exactly like rebuild_all and the loop-path on_write already do. (Writing only the folder, as the CLI used to, left stale layer/root counts that validate would then flag as an index desync.)

Source

pub fn write_level(store: &Store, level: &IndexLevel) -> Result<()>

Atomically write a single level’s artifact(s) to disk.

Source

pub fn render_dry_run(store: &Store, level: &IndexLevel) -> Result<String>

Render the generated indexes to a string with --- <path> --- separators instead of writing them (--dry-run).

Source

pub fn cleanup(store: &Store) -> Result<()>

Cleanup pass (part of Index::rebuild_all): delete index.md / index.jsonl in non-canonical folders (date-shards that should carry none). Symmetric with index creation.

Only deletes generated catalog artifacts, never user content. Two guards keep this from eating data:

  • min_depth(2) so the walk starts below the type-folder root — the canonical <type-folder>/index.md + index.jsonl are never targeted here (they are rewritten by the per-folder builders, or removed only when the folder is genuinely empty, in the dedicated branch below). The old min_depth(1) deleted them up front, so a rebuild aborted by one malformed file left every type-folder catalog destroyed.
  • [is_deletable_catalog_artifact] confirms a shard-level index.md is an actual generated catalog (or stale/garbage leftover), NOT a content file a user wrote at that name (e.g. dbmd write …/index.md --type email, plausible when mirroring a website/doc export). Matching by filename alone silently deleted such records on the next rebuild.

Trait Implementations§

Source§

impl Clone for Index

Source§

fn clone(&self) -> Index

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 Index

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Index

Source§

fn eq(&self, other: &Index) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Index

Auto Trait Implementations§

§

impl Freeze for Index

§

impl RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnsafeUnpin for Index

§

impl UnwindSafe for Index

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<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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.