#[non_exhaustive]pub struct IndexSpec {
pub name: String,
pub kind: IndexKind,
pub key_paths: Vec<String>,
}Expand description
A runtime index declaration.
Document::indexes() returns a Vec<IndexSpec>; the catalog
reconciler in #57 compares this list against the catalog’s stored
crate::catalog::IndexDescriptor rows and declares or drops
the difference.
§Construction
Prefer the kind-specific constructors over building the struct literal — they enforce the per-kind path-count invariants:
use obj_core::index::IndexSpec;
// Standard / Unique / Each take exactly one field path.
let by_email_unique = IndexSpec::unique("by_email", "email").expect("valid");
let by_status = IndexSpec::standard("by_status", "status").expect("valid");
let by_tag = IndexSpec::each("by_tag", "tags").expect("valid");
// Composite requires two or more.
let by_customer_time = IndexSpec::composite(
"by_customer_time",
&["customer_id", "placed_at"],
).expect("valid");Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: StringUser-visible name. Stable across reopens; the catalog uses it to match a runtime spec against an on-disk descriptor.
kind: IndexKindDiscriminator. See IndexKind.
key_paths: Vec<String>Field path(s) within the document. Single-element for
Standard / Unique / Each; ≥ 2 for Composite.
Implementations§
Source§impl IndexSpec
impl IndexSpec
Sourcepub fn standard<N: Into<String>, P: Into<String>>(
name: N,
path: P,
) -> Result<Self>
pub fn standard<N: Into<String>, P: Into<String>>( name: N, path: P, ) -> Result<Self>
Construct a IndexKind::Standard spec.
§Errors
Returns Error::InvalidArgument if name or path is empty.
Sourcepub fn each<N: Into<String>, P: Into<String>>(name: N, path: P) -> Result<Self>
pub fn each<N: Into<String>, P: Into<String>>(name: N, path: P) -> Result<Self>
Construct a IndexKind::Each spec. The indexed field MUST
be a sequence-valued field at extract time; if it is not,
extract_index_keys (#56) errors with
Error::IndexFieldTypeMismatch.
§Errors
Sourcepub fn composite<N: Into<String>>(name: N, paths: &[&str]) -> Result<Self>
pub fn composite<N: Into<String>>(name: N, paths: &[&str]) -> Result<Self>
Construct a IndexKind::Composite spec.
§Errors
Returns Error::InvalidArgument if name is empty, if
paths has fewer than two entries, or if any path is empty.
Sourcepub fn from_parts<N: Into<String>>(
name: N,
kind: IndexKind,
key_paths: Vec<String>,
) -> Result<Self>
pub fn from_parts<N: Into<String>>( name: N, kind: IndexKind, key_paths: Vec<String>, ) -> Result<Self>
Construct a spec from its individual parts.
Unlike the kind-specific constructors, this accepts an
arbitrary IndexKind plus a key_paths vector and is the
general entry point callers reach for when reconstructing a
spec from an on-disk crate::catalog::IndexDescriptor (where
the kind is data, not a compile-time choice). The result is
validated, so a malformed
descriptor surfaces as an error rather than a silently-wrong
spec.
§Errors
Returns Error::InvalidArgument if name is empty, any path
is empty, or the path count disagrees with the kind.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate the spec’s shape against the per-kind invariants.
Called by every constructor; safe to call again on a round-tripped (postcard-decoded) spec as a defense-in-depth check before the catalog stamps the descriptor.
§Errors
Error::InvalidArgumentifnameis empty, any path is empty, or the path count disagrees with the kind.