Skip to main content

ZanzibarEngine

Struct ZanzibarEngine 

Source
pub struct ZanzibarEngine { /* private fields */ }
Expand description

Public local Zanzibar engine.

Reads clone immutable published snapshots through an atomic pointer and do not acquire a service-level lock. Writes are submitted to one bounded writer actor that owns the mutable schema, relationship store, and revision history for this engine instance.

Implementations§

Source§

impl ZanzibarEngine

Source

pub fn builder() -> ZanzibarEngineBuilder

Creates a builder for a local engine.

Source

pub fn check(&self, request: CheckRequest) -> Result<CheckResponse, EngineError>

Checks whether a subject has a relation or permission on an object.

§Errors

Returns EngineError when request validation, consistency, store access, or evaluation fails.

Source

pub fn check_relation( &self, object: &Object, relation: &Relation, user: &User, ) -> Result<bool, EngineError>

Checks a relation or permission using latest consistency.

§Errors

Returns EngineError when request validation, consistency, store access, or evaluation fails.

Source

pub fn check_relation_with_consistency( &self, object: &Object, relation: &Relation, user: &User, consistency: Consistency, ) -> Result<bool, EngineError>

Checks a relation or permission at the requested consistency.

§Errors

Returns EngineError when request validation, consistency, store access, or evaluation fails.

Source

pub fn check_with_consistency( &self, object: &Object, relation: &Relation, user: &User, consistency: Consistency, ) -> Result<bool, EngineError>

Checks a relation or permission at the requested consistency.

This convenience method is equivalent to Self::check_relation_with_consistency.

§Errors

Returns EngineError when request validation, consistency, store access, or evaluation fails.

Source

pub fn expand( &self, request: ExpandRequest, ) -> Result<ExpandResponse, EngineError>

Expands the effective userset for an object relation or permission.

§Errors

Returns EngineError when request validation, consistency, store access, or evaluation fails.

Source

pub fn expand_relation( &self, object: &Object, relation: &Relation, ) -> Result<ExpandedUserset, EngineError>

Expands a relation or permission using latest consistency.

§Errors

Returns EngineError when request validation, consistency, store access, or evaluation fails.

Source

pub fn lookup_resources( &self, request: impl Borrow<LookupResourcesRequest>, ) -> Result<LookupResources, EngineError>

Looks up resources of a type that a subject can access at latest consistency.

§Errors

Returns EngineError when request validation, store access, or evaluation fails.

Source

pub fn lookup_resources_with_consistency( &self, request: impl Borrow<LookupResourcesRequest>, consistency: Consistency, ) -> Result<LookupResources, EngineError>

Looks up resources of a type at the requested consistency.

§Errors

Returns EngineError when request validation, consistency, store access, or evaluation fails.

Source

pub fn lookup_subjects( &self, request: impl Borrow<LookupSubjectsRequest>, ) -> Result<LookupSubjects, EngineError>

Looks up subjects of a type that can access a resource at latest consistency.

§Errors

Returns EngineError when request validation, store access, or evaluation fails.

Source

pub fn lookup_subjects_with_consistency( &self, request: impl Borrow<LookupSubjectsRequest>, consistency: Consistency, ) -> Result<LookupSubjects, EngineError>

Looks up subjects of a type at the requested consistency.

§Errors

Returns EngineError when request validation, consistency, store access, or evaluation fails.

Source

pub fn bench_relationship_delta_stats( &self, consistency: Consistency, ) -> Result<StoreViewDeltaStats, EngineError>

Returns benchmark-only delta stats for the selected snapshot.

§Errors

Returns EngineError when the requested consistency cannot be resolved.

Source

pub fn bench_relationship_posting_histograms( &self, consistency: Consistency, ) -> Result<StorePostingHistograms, EngineError>

Returns benchmark-only posting histograms for the selected snapshot.

§Errors

Returns EngineError when the requested consistency cannot be resolved.

Source

pub fn write_relationships( &self, mutations: impl IntoIterator<Item = RelationshipMutation>, ) -> Result<ConsistencyToken, EngineError>

Applies relationship mutations and publishes a new revision.

§Errors

Returns EngineError when no schema is loaded, validation fails, or mutation semantics are invalid.

Source

pub fn apply_relationship_mutations( &self, mutations: impl IntoIterator<Item = RelationshipMutation>, preconditions: impl IntoIterator<Item = Precondition>, ) -> Result<ConsistencyToken, EngineError>

Applies relationship mutations with optional preconditions.

This is an alias for Self::write_relationships_with_preconditions kept as the explicit batch mutation verb in the public API.

§Errors

Returns EngineError when no schema is loaded, validation fails, preconditions fail, or mutation semantics are invalid.

Source

pub fn write_tuple( &self, tuple: impl Borrow<RelationTuple>, ) -> Result<(), EngineError>

Writes one legacy tuple as an idempotent relationship touch.

Prefer Self::write_relationships for high-throughput callers because it batches many mutations into one writer-actor turn.

§Errors

Returns EngineError when the tuple is invalid, no schema is loaded, or validation fails.

Source

pub fn write_tuple_with_token( &self, tuple: &RelationTuple, ) -> Result<ConsistencyToken, EngineError>

Writes one legacy tuple as an idempotent relationship touch and returns the published token.

§Errors

Returns EngineError when the tuple is invalid, no schema is loaded, or validation fails.

Source

pub fn delete_tuple(&self, tuple: &RelationTuple) -> Result<(), EngineError>

Deletes one legacy tuple.

§Errors

Returns EngineError when the tuple is invalid, no schema is loaded, validation fails, or the tuple is absent.

Source

pub fn delete_tuple_with_token( &self, tuple: &RelationTuple, ) -> Result<ConsistencyToken, EngineError>

Deletes one legacy tuple and returns the published token.

§Errors

Returns EngineError when the tuple is invalid, no schema is loaded, validation fails, or the tuple is absent.

Source

pub fn create_relationship( &self, relationship: &str, ) -> Result<ConsistencyToken, EngineError>

Creates one relationship, failing if it already exists.

§Errors

Returns EngineError when the relationship text is invalid, no schema is loaded, validation fails, or the relationship already exists.

Source

pub fn touch_relationship( &self, relationship: &str, ) -> Result<ConsistencyToken, EngineError>

Grants or refreshes one relationship idempotently.

§Errors

Returns EngineError when the relationship text is invalid, no schema is loaded, or validation fails.

Source

pub fn delete_relationship( &self, relationship: &str, ) -> Result<ConsistencyToken, EngineError>

Deletes one relationship, failing if it does not exist.

§Errors

Returns EngineError when the relationship text is invalid, no schema is loaded, validation fails, or the relationship does not exist.

Source

pub fn write_relationships_with_preconditions( &self, mutations: impl IntoIterator<Item = RelationshipMutation>, preconditions: impl IntoIterator<Item = Precondition>, ) -> Result<ConsistencyToken, EngineError>

Applies relationship mutations with preconditions and publishes a new revision.

§Errors

Returns EngineError when no schema is loaded, validation fails, preconditions fail, or mutation semantics are invalid.

Source

pub fn apply_schema( &self, source: SchemaSource<'_>, ) -> Result<ConsistencyToken, EngineError>

Applies a schema document and publishes a new revision.

§Errors

Returns EngineError when the schema cannot be parsed or validated.

Source

pub fn add_dsl(&self, dsl: &str) -> Result<(), EngineError>

Applies a legacy DSL schema document and publishes a new revision.

§Errors

Returns EngineError when the DSL cannot be parsed or validated.

Source

pub fn add_dsl_with_token( &self, dsl: &str, ) -> Result<ConsistencyToken, EngineError>

Applies a legacy DSL schema document and returns the published token.

§Errors

Returns EngineError when the DSL cannot be parsed or validated.

Source

pub fn apply_namespace_config( &self, config: NamespaceConfig, ) -> Result<ConsistencyToken, EngineError>

Applies one structured namespace config and publishes a new revision.

§Errors

Returns EngineError when the namespace config cannot be validated.

Source

pub fn add_config_with_token( &self, config: NamespaceConfig, ) -> Result<ConsistencyToken, EngineError>

Applies one structured namespace config and returns the published token.

§Errors

Returns EngineError when the namespace config cannot be validated.

Source

pub fn apply_namespace_configs( &self, configs: impl IntoIterator<Item = NamespaceConfig>, ) -> Result<ConsistencyToken, EngineError>

Applies structured namespace configs and publishes a single new revision.

§Errors

Returns EngineError when any namespace config cannot be validated.

Source

pub fn replace_schema( &self, source: SchemaSource<'_>, ) -> Result<ConsistencyToken, EngineError>

Replaces the complete schema document and publishes a new revision.

§Errors

Returns EngineError when the schema cannot be parsed or existing relationships no longer validate against it.

Source

pub fn delete_namespace( &self, namespace: &str, ) -> Result<ConsistencyToken, EngineError>

Deletes one namespace definition.

§Errors

Returns EngineError when the namespace is missing or existing relationships still reference it.

Source

pub fn delete_relation( &self, namespace: &str, relation: &str, ) -> Result<ConsistencyToken, EngineError>

Deletes one relation definition.

§Errors

Returns EngineError when the relation is missing or existing relationships still reference it.

Source

pub fn from_policy_text(policy: &PolicyText) -> Result<Self, EngineError>

Builds a new engine from policy text.

§Errors

Returns EngineError when policy text cannot be parsed or validated.

Source

pub fn apply_policy_text( &self, policy: &PolicyText, ) -> Result<ConsistencyToken, EngineError>

Replaces this engine’s state with policy text.

§Errors

Returns EngineError when policy text cannot be parsed or validated.

Source

pub fn save_snapshot_from_policy_text( path: impl AsRef<Path>, policy: &PolicyText, options: SnapshotSaveOptions, ) -> Result<(), PolicyIoError>

Saves a snapshot built from policy text without keeping an engine.

§Errors

Returns PolicyIoError when policy parsing or snapshot writing fails.

Source

pub fn export_policy_text(&self) -> Result<PolicyText, EngineError>

Exports the latest state as deterministic policy text.

§Errors

Returns EngineError when no schema has been loaded.

Source

pub fn export_policy_files( &self, directory: impl AsRef<Path>, ) -> Result<(), PolicyIoError>

Exports deterministic policy files under directory.

§Errors

Returns PolicyIoError when no schema has been loaded or file output fails.

Source

pub fn lookup_permissions( &self, request: impl Borrow<LookupPermissionsRequest>, ) -> Result<LookupPermissions, EngineError>

Looks up every relation or permission a subject has on one resource.

§Errors

Returns EngineError when request validation or evaluation fails.

Source

pub fn lookup_object_permissions( &self, request: impl Borrow<LookupObjectPermissionsRequest>, ) -> Result<LookupObjectPermissions, EngineError>

Looks up subjects grouped by every relation or permission they have on one resource.

§Errors

Returns EngineError when request validation, store access, or evaluation fails.

Source

pub fn save_snapshot( &self, path: impl AsRef<Path>, options: SnapshotSaveOptions, ) -> Result<(), SnapshotIoError>

Saves the latest published snapshot to a versioned .szsnap artifact.

§Errors

Returns SnapshotIoError when no schema is loaded, the save options are unsupported, or the artifact cannot be written.

Source

pub fn load_snapshot( path: impl AsRef<Path>, options: SnapshotLoadOptions, ) -> Result<Self, SnapshotIoError>

Loads a versioned .szsnap artifact into a new engine.

§Errors

Returns SnapshotIoError when the artifact cannot be read or fails validation.

Trait Implementations§

Source§

impl Debug for ZanzibarEngine

Source§

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

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

impl Default for ZanzibarEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more