Skip to main content

TemplateRenderer

Struct TemplateRenderer 

Source
pub struct TemplateRenderer;
Expand description

Template context renderer producing structured JSON from service definitions.

Translates a ServiceDef into a flat, semantic JSON object that template engines can consume directly. Intent scores and render context are ignored — the output is intent-agnostic per design (D-01 through D-08).

§Output shape

{
  "service": "Order",
  "fields": {
    "total": { "name": "total", "data_type": "float", "meaning": "money", "required": true }
  },
  "actions": [
    { "name": "submit", "display_name": "Submit", "inputs": [] }
  ],
  "state_machine": {
    "initial_state": "draft",
    "states": [{ "name": "draft", "display_name": "Draft", "is_final": false }],
    "transitions": [{ "from": "draft", "event": "submit", "to": "pending" }]
  }
}

state_machine is null when the service has no state machine.

§Example

use ferro_projections::{
    ServiceDef, DataType, FieldMeaning, derive_intents, TemplateRenderer, Renderer, BaseContext,
};

let svc = ServiceDef::new("order")
    .display_name("Order")
    .field("id", DataType::Integer, FieldMeaning::Identifier)
    .field("total", DataType::Float, FieldMeaning::Money);

let intents = derive_intents(&svc);
let renderer = TemplateRenderer;
let result = renderer.render(&svc, &intents, &BaseContext::default());
assert!(result.is_ok());

let json = result.unwrap();
assert_eq!(json["service"], "Order");
assert!(json["fields"]["total"].is_object());
assert!(!json["fields"].as_object().unwrap().contains_key("id"));

Trait Implementations§

Source§

impl Renderer for TemplateRenderer

Source§

type Output = Value

The output type produced by this renderer (e.g., serde_json::Value).
Source§

type Context = BaseContext

The context type consumed by this renderer. Must implement Default.
Source§

fn render( &self, service: &ServiceDef, _intents: &[IntentScore], _ctx: &BaseContext, ) -> Result<Value, Error>

Renders a service definition into the renderer’s output 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, 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.