Skip to main content

IndexSpec

Struct IndexSpec 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: String

User-visible name. Stable across reopens; the catalog uses it to match a runtime spec against an on-disk descriptor.

§kind: IndexKind

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

Source

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.

Source

pub fn unique<N: Into<String>, P: Into<String>>( name: N, path: P, ) -> Result<Self>

Construct a IndexKind::Unique spec.

§Errors

As IndexSpec::standard.

Source

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

As IndexSpec::standard.

Source

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.

Source

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.

Source

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

Trait Implementations§

Source§

impl Clone for IndexSpec

Source§

fn clone(&self) -> IndexSpec

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 IndexSpec

Source§

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

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

impl<'de> Deserialize<'de> for IndexSpec

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for IndexSpec

Source§

fn eq(&self, other: &IndexSpec) -> 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 Serialize for IndexSpec

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for IndexSpec

Source§

impl StructuralPartialEq for IndexSpec

Auto Trait Implementations§

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> 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,