Skip to main content

ServiceDef

Struct ServiceDef 

Source
pub struct ServiceDef {
    pub name: String,
    pub display_name: Option<String>,
    pub description: Option<String>,
    pub fields: Vec<FieldDef>,
    pub actions: Vec<ActionDef>,
    pub guards: Vec<GuardDef>,
    pub relationships: Vec<RelationshipDef>,
    pub intent_hints: Vec<IntentHint>,
    pub state_machine: Option<StateMachine>,
}
Expand description

A service definition describing a domain entity and its fields.

Constructed via a builder API with method chaining:

use ferro_projections::{ServiceDef, DataType, FieldMeaning};

let order = ServiceDef::new("order")
    .display_name("Order")
    .description("Manages customer orders")
    .field("id", DataType::Integer, FieldMeaning::Identifier)
    .field("total", DataType::Float, FieldMeaning::Money)
    .optional_field("notes", DataType::String, FieldMeaning::FreeText);

Fields§

§name: String§display_name: Option<String>§description: Option<String>§fields: Vec<FieldDef>§actions: Vec<ActionDef>§guards: Vec<GuardDef>§relationships: Vec<RelationshipDef>§intent_hints: Vec<IntentHint>§state_machine: Option<StateMachine>

Implementations§

Source§

impl ServiceDef

Source

pub fn new(name: impl Into<String>) -> Self

Creates a new service definition with the given name.

Source

pub fn display_name(self, name: impl Into<String>) -> Self

Sets the human-readable display name.

Source

pub fn description(self, desc: impl Into<String>) -> Self

Sets the service description.

Source

pub fn field( self, name: impl Into<String>, data_type: DataType, meaning: FieldMeaning, ) -> Self

Adds a required read-write field.

Source

pub fn optional_field( self, name: impl Into<String>, data_type: DataType, meaning: FieldMeaning, ) -> Self

Adds an optional (nullable) read-write field.

Source

pub fn list_field( self, name: impl Into<String>, data_type: DataType, meaning: FieldMeaning, ) -> Self

Adds a required read-write list field.

Source

pub fn read_only_field( self, name: impl Into<String>, data_type: DataType, meaning: FieldMeaning, ) -> Self

Adds a required read-only field (readable but not writable).

For system-assigned or computed fields like id, created_at, or totals.

Source

pub fn write_only_field( self, name: impl Into<String>, data_type: DataType, meaning: FieldMeaning, ) -> Self

Adds a required write-only field (writable but not readable).

For sensitive inputs like passwords or API keys that should not be read back.

Source

pub fn action(self, action: ActionDef) -> Self

Adds an action definition to this service.

Source

pub fn guard(self, guard: GuardDef) -> Self

Adds a guard definition to this service.

Source

pub fn relationship(self, rel: RelationshipDef) -> Self

Adds a relationship definition to this service.

Source

pub fn belongs_to( self, name: impl Into<String>, target: impl Into<String>, ) -> Self

Adds a many-to-one relationship (this service belongs to target).

Source

pub fn has_many( self, name: impl Into<String>, target: impl Into<String>, ) -> Self

Adds a one-to-many relationship (this service has many of target).

Source

pub fn has_one(self, name: impl Into<String>, target: impl Into<String>) -> Self

Adds a one-to-one relationship (this service has one of target).

Source

pub fn belongs_to_many( self, name: impl Into<String>, target: impl Into<String>, ) -> Self

Adds a many-to-many relationship (this service belongs to many of target).

Source

pub fn intent_hint(self, hint: IntentHint) -> Self

Adds an intent hint for overriding structural derivation.

Source

pub fn state_machine(self, machine: StateMachine) -> Self

Sets the state machine definition for this service.

Source

pub fn from_model(meta: &ModelMetadata) -> Self

Derives a ServiceDef from model metadata.

Infers DataType from column type strings and FieldMeaning from field names. System fields (id, created_at, updated_at, primary keys) are marked read-only. Actions, state machines, and relationships are not derived.

Source

pub fn validate(&self) -> Result<Vec<Warning>, Error>

Validates the service definition and returns warnings for potential issues.

This is the single validation entry point that subsumes StateMachine::validate(). Guard names form a shared pool referenced from transitions and action preconditions.

Returns Err for fatal issues (undefined guard references, unmatched triggers). Returns Ok(warnings) for structural concerns (unused guards, missing state machine).

Trait Implementations§

Source§

impl Clone for ServiceDef

Source§

fn clone(&self) -> ServiceDef

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServiceDef

Source§

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

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

impl<'de> Deserialize<'de> for ServiceDef

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 JsonSchema for ServiceDef

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for ServiceDef

Source§

fn eq(&self, other: &ServiceDef) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 ServiceDef

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 StructuralPartialEq for ServiceDef

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,