Skip to main content

SchemaBuilder

Struct SchemaBuilder 

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

A builder for incrementally constructing a validated Schema.

§Example

let schema = SchemaBuilder::new(&protocol)
    .vertex("post", "record", Some("app.bsky.feed.post"))?
    .vertex("post:body", "object", None)?
    .edge("post", "post:body", "record-schema", None)?
    .build()?;

Implementations§

Source§

impl SchemaBuilder

Source

pub fn new(protocol: &Protocol) -> Self

Create a new builder for the given protocol.

Source

pub fn vertex( self, id: &str, kind: &str, nsid: Option<&str>, ) -> Result<Self, SchemaError>

Add a vertex to the schema.

§Errors

Returns SchemaError::DuplicateVertex if a vertex with the same ID already exists, or SchemaError::UnknownVertexKind if the kind is not recognized by the protocol.

Source

pub fn edge( self, src: &str, tgt: &str, kind: &str, name: Option<&str>, ) -> Result<Self, SchemaError>

Add a binary edge to the schema.

Validates that:

  • Both src and tgt vertices exist
  • The edge kind is recognized by the protocol
  • The source and target vertex kinds satisfy the edge rule
§Errors

Returns SchemaError::VertexNotFound, SchemaError::UnknownEdgeKind, SchemaError::InvalidEdgeSource, or SchemaError::InvalidEdgeTarget.

Source

pub fn hyper_edge( self, id: &str, kind: &str, sig: HashMap<String, String>, parent: &str, ) -> Result<Self, SchemaError>

Add a hyper-edge to the schema.

§Errors

Returns SchemaError::DuplicateHyperEdge if a hyper-edge with the same ID already exists, or SchemaError::VertexNotFound if any vertex in the signature is missing.

Source

pub fn constraint(self, vertex: &str, sort: &str, value: &str) -> Self

Add a constraint to a vertex.

Constraints are not validated during building; use validate to check them against the protocol’s constraint sorts.

Source

pub fn required(self, vertex: &str, edges: Vec<Edge>) -> Self

Declare required edges for a vertex.

Source

pub fn coercion( self, source_kind: &str, target_kind: &str, spec: CoercionSpec, ) -> Self

Add a coercion specification for a (source_kind, target_kind) pair.

Source

pub fn merger(self, vertex_id: &str, expr: Expr) -> Self

Add a merger expression for a vertex.

Source

pub fn default_expr(self, vertex_id: &str, expr: Expr) -> Self

Add a default value expression for a vertex.

Source

pub fn policy(self, sort_name: &str, expr: Expr) -> Self

Add a conflict resolution policy expression for a sort.

Source

pub fn build(self) -> Result<Schema, SchemaError>

Consume the builder and produce a validated Schema with precomputed adjacency indices.

§Errors

Returns SchemaError::EmptySchema if no vertices were added.

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