Skip to main content

GraphBuilder

Struct GraphBuilder 

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

Builder for a single Limen graph AST (ast::GraphDef).

GraphBuilder collects nodes and edges with precise typing, so you get full IDE completion and compiler checking while authoring graphs in build.rs.

Implementations§

Source§

impl GraphBuilder

Source

pub fn new(name: &str, vis: GraphVisibility) -> Self

Create a new graph builder.

§Parameters
  • name: graph type name as an identifier string (e.g. "MyGraph").
  • vis: a GraphVisibility enum controlling pub / pub(crate) / pub(super) / private.

This convenience avoids calling syn::parse_quote in build.rs; we synthesize a syn::Visibility internally.

Source

pub fn node(self, n: Node) -> Self

Append a fully specified node to the graph.

The Node parameter is a fluent sub-builder; it is converted to an ast::NodeDef at call time.

§Examples
use limen_codegen::builder::{GraphBuilder, GraphVisibility, Node};

let gb = GraphBuilder::new("MyGraph", GraphVisibility::Public)
    .node(
        Node::new(0)
            .ty::<MySource>()
            .in_ports(0)
            .out_ports(1)
            .in_payload::<()>()
            .out_payload::<u32>()
    );

Append a Node described by a core NodeLink — the builder extracts its type, payload types, id, and optional name and constructs an AST ast::NodeDef entry.

ingress_policy is optional; supply it for source nodes.

Source

pub fn edge(self, e: Edge) -> Self

Append a fully specified edge to the graph.

The Edge parameter is a fluent sub-builder; it is converted to an ast::EdgeDef at call time.

§Examples
use limen_codegen::builder::{GraphBuilder, GraphVisibility, Edge};
use limen_core::policy::{AdmissionPolicy, EdgePolicy, OverBudgetAction, QueueCaps};

let policy = EdgePolicy::new(
    QueueCaps::new(8, 6, None, None),
    AdmissionPolicy::DropNewest,
    OverBudgetAction::Drop,
);

let gb = GraphBuilder::new("MyGraph", GraphVisibility::Public)
    .edge(
        Edge::new(0)
            .ty::<limen_core::edge::spsc_array::StaticRing<8>>()
            .payload::<u32>()
            .manager_ty::<limen_core::memory::static_manager::StaticMemoryManager<u32, 8>>()
            .from(0, 0)
            .to(1, 0)
            .policy(policy)
            .name(Some("source->map"))
    );

Append an Edge described by a core EdgeLink. The builder extracts the queue type, endpoints, policy, and id and converts them into an ast::EdgeDef.

The payload type P and memory manager type M must be supplied explicitly because EdgeLink does not carry them.

Source

pub fn concurrent(self, emit_concurrent: bool) -> Self

Control whether to emit the std-only scoped execution API (ScopedGraphApi) for the generated graph.

This does not change the graph structure. It only controls whether codegen emits the extra run_scoped(..) implementation.

Source

pub fn to_graph_def(self) -> GraphDef

Finalize and produce the ast::GraphDef.

This consumes the builder and returns a complete graph AST suitable for code generation.

§Panics

Panics if the builder was not created via GraphBuilder::new, or if vis or name were not set.

Source

pub fn finish(self) -> GraphWriter

Finalize and produce a GeneratedGraph that owns the AST and can write it to file.

Trait Implementations§

Source§

impl Default for GraphBuilder

Source§

fn default() -> GraphBuilder

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