[][src]Trait moore::score::NodeMaker

pub trait NodeMaker<I, N> {
    pub fn make(&self, id: I) -> Result<N, ()>;
}

The NodeMaker trait allows for nodes to be generated from an ID.

This is useful in conjunction with the NodeStorage and Scoreboard traits. If a value is requested that the scoreboard cannot find, this trait allows for the node to be generated. For example, if the AST for a node is requested but does not exist, this trait can be implemented in such a way that said AST is loaded. This allows for complex on-demand loading and compilation to be implemented.

The nodes are expected to be owned either by the caller or some arena. Therefore only a reference to the created node is returned.

Example

use moore_common::score::{self, NodeMaker};

#[derive(PartialEq, Eq, Debug)]
struct Foo;
#[derive(PartialEq, Eq, Debug)]
struct Bar;

struct FooId(usize);
struct BarId(usize);

struct Table;

impl<'tn> NodeMaker<FooId, &'tn Foo> for Table {
    fn make(&self, id: FooId) -> score::Result<&'tn Foo> {
        static FOO: Foo = Foo;
        Ok(&FOO) // usually you would allocate this in an arena
    }
}

impl<'tn> NodeMaker<BarId, &'tn Bar> for Table {
    fn make(&self, id: BarId) -> score::Result<&'tn Bar> {
        static BAR: Bar = Bar;
        Ok(&BAR) // usually you would allocate this in an arena
    }
}

let tbl = Table;
let foo = tbl.make(FooId(1)).unwrap();
let bar = tbl.make(BarId(2)).unwrap();
assert_eq!(foo, &Foo);
assert_eq!(bar, &Bar);

// The following would produce a compiler error due to type mismatch:
// assert_eq!(foo, &Bar);
// assert_eq!(bar, &Foo);

Required methods

pub fn make(&self, id: I) -> Result<N, ()>[src]

Creates the node with the given ID.

Returns Err(()) upon failure. Note that the generated node has lifetime 'tn that outlives the NodeMaker. This is required to allow for the NodeMaker to generate multiple nodes at the same time. The generated nodes should be owned by an arena or the owner of the NodeMaker itself.

Loading content...

Implementations on Foreign Types

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<IntfSignalRef, &'ctx IntfSignal> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ArchRef, UnitId> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ScopeRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ArchRef, &'ctx Arch> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ProcessStmtRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>, Global>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<EntityRef, &'ctx Entity> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<IntfVarRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<PkgDeclRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<PkgBodyRef, &'ctx PackageBody> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<CtxItemsRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>, Global>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SignalRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<PkgDeclRef, &'ctx Package> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubtypeDeclRef, &'ctx SubtypeDecl> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<LibRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubprogBodyRef, &'ctx SubprogBody> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ArrayTypeIndexRef, &'ctx Spanned<ArrayTypeIndex>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<LibRef, &'ctx ArchTable> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubtypeIndRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<TypeDeclRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubprogInstRef, &'ctx SubprogInst> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ArchRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ScopeRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>, Global>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<PkgDeclRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>, Global>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<CtxItemsRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<IntfConstRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubtypeDeclRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<IntfObjRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ArchRef, DeclValueRef> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<TypeMarkRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ProcessStmtRef, &'ctx ProcessStmt> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<PkgBodyRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>, Global>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubprogDeclRef, &'ctx Subprog> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<PkgInstRef, &'ctx PackageInst> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ProcessStmtRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<LibRef, &'ctx Lib> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<TypedNodeRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<LibRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>, Global>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<PkgBodyRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<EntityRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubprogBodyRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<LatentTypeMarkRef, Spanned<TypeMarkRef>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubprogDeclRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>, Global>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<LatentTypeMarkRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<IntfSignalRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SigAssignStmtRef, &'ctx SigAssignStmt> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubprogBodyRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>, Global>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ArchRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>, Global>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<EntityRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>, Global>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubprogDeclRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<IntfFileRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ExprRef, &'ctx Const> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

Loading content...

Implementors

impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ScopeRef, &'ctx HashMap<Name, Def, RandomState>> for moore::score::ScoreContext<'lazy, 'sb, 'ast, 'ctx>[src]

Loading content...