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
impl ZanzibarEngine
Sourcepub fn builder() -> ZanzibarEngineBuilder
pub fn builder() -> ZanzibarEngineBuilder
Creates a builder for a local engine.
Sourcepub fn check(&self, request: CheckRequest) -> Result<CheckResponse, EngineError>
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.
Sourcepub fn check_relation(
&self,
object: &Object,
relation: &Relation,
user: &User,
) -> Result<bool, EngineError>
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.
Sourcepub fn check_relation_with_consistency(
&self,
object: &Object,
relation: &Relation,
user: &User,
consistency: Consistency,
) -> Result<bool, EngineError>
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.
Sourcepub fn check_with_consistency(
&self,
object: &Object,
relation: &Relation,
user: &User,
consistency: Consistency,
) -> Result<bool, EngineError>
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.
Sourcepub fn expand(
&self,
request: ExpandRequest,
) -> Result<ExpandResponse, EngineError>
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.
Sourcepub fn expand_relation(
&self,
object: &Object,
relation: &Relation,
) -> Result<ExpandedUserset, EngineError>
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.
Sourcepub fn lookup_resources(
&self,
request: impl Borrow<LookupResourcesRequest>,
) -> Result<LookupResources, EngineError>
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.
Sourcepub fn lookup_resources_with_consistency(
&self,
request: impl Borrow<LookupResourcesRequest>,
consistency: Consistency,
) -> Result<LookupResources, EngineError>
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.
Sourcepub fn lookup_subjects(
&self,
request: impl Borrow<LookupSubjectsRequest>,
) -> Result<LookupSubjects, EngineError>
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.
Sourcepub fn lookup_subjects_with_consistency(
&self,
request: impl Borrow<LookupSubjectsRequest>,
consistency: Consistency,
) -> Result<LookupSubjects, EngineError>
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.
Sourcepub fn bench_relationship_delta_stats(
&self,
consistency: Consistency,
) -> Result<StoreViewDeltaStats, EngineError>
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.
Sourcepub fn bench_relationship_posting_histograms(
&self,
consistency: Consistency,
) -> Result<StorePostingHistograms, EngineError>
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.
Sourcepub fn write_relationships(
&self,
mutations: impl IntoIterator<Item = RelationshipMutation>,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn apply_relationship_mutations(
&self,
mutations: impl IntoIterator<Item = RelationshipMutation>,
preconditions: impl IntoIterator<Item = Precondition>,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn write_tuple(
&self,
tuple: impl Borrow<RelationTuple>,
) -> Result<(), EngineError>
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.
Sourcepub fn write_tuple_with_token(
&self,
tuple: &RelationTuple,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn delete_tuple(&self, tuple: &RelationTuple) -> Result<(), EngineError>
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.
Sourcepub fn delete_tuple_with_token(
&self,
tuple: &RelationTuple,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn create_relationship(
&self,
relationship: &str,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn touch_relationship(
&self,
relationship: &str,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn delete_relationship(
&self,
relationship: &str,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn write_relationships_with_preconditions(
&self,
mutations: impl IntoIterator<Item = RelationshipMutation>,
preconditions: impl IntoIterator<Item = Precondition>,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn apply_schema(
&self,
source: SchemaSource<'_>,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn add_dsl(&self, dsl: &str) -> Result<(), EngineError>
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.
Sourcepub fn add_dsl_with_token(
&self,
dsl: &str,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn apply_namespace_config(
&self,
config: NamespaceConfig,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn add_config_with_token(
&self,
config: NamespaceConfig,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn apply_namespace_configs(
&self,
configs: impl IntoIterator<Item = NamespaceConfig>,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn replace_schema(
&self,
source: SchemaSource<'_>,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn delete_namespace(
&self,
namespace: &str,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn delete_relation(
&self,
namespace: &str,
relation: &str,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn from_policy_text(policy: &PolicyText) -> Result<Self, EngineError>
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.
Sourcepub fn apply_policy_text(
&self,
policy: &PolicyText,
) -> Result<ConsistencyToken, EngineError>
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.
Sourcepub fn save_snapshot_from_policy_text(
path: impl AsRef<Path>,
policy: &PolicyText,
options: SnapshotSaveOptions,
) -> Result<(), PolicyIoError>
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.
Sourcepub fn export_policy_text(&self) -> Result<PolicyText, EngineError>
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.
Sourcepub fn export_policy_files(
&self,
directory: impl AsRef<Path>,
) -> Result<(), PolicyIoError>
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.
Sourcepub fn lookup_permissions(
&self,
request: impl Borrow<LookupPermissionsRequest>,
) -> Result<LookupPermissions, EngineError>
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.
Sourcepub fn lookup_object_permissions(
&self,
request: impl Borrow<LookupObjectPermissionsRequest>,
) -> Result<LookupObjectPermissions, EngineError>
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.
Sourcepub fn save_snapshot(
&self,
path: impl AsRef<Path>,
options: SnapshotSaveOptions,
) -> Result<(), SnapshotIoError>
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.
Sourcepub fn load_snapshot(
path: impl AsRef<Path>,
options: SnapshotLoadOptions,
) -> Result<Self, SnapshotIoError>
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.