[−][src]Trait moore::score::NodeMaker
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> { Ok(unsafe { &*(1 as *const 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> { Ok(unsafe { &*(1 as *const 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
fn make(&self, id: I) -> Result<N, ()>
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.
Implementations on Foreign Types
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubprogDeclRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SigAssignStmtRef, &'ctx SigAssignStmt> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(&self, id: SigAssignStmtRef) -> Result<&'ctx SigAssignStmt, ()>
[src]
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<TypeDeclRef, &'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]
fn make(&self, id: ProcessStmtRef) -> Result<&'ctx ProcessStmt, ()>
[src]
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<LibRef, &'ctx ArchTable> 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<LatentTypeMarkRef, Spanned<TypeMarkRef>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(&self, id: LatentTypeMarkRef) -> Result<Spanned<TypeMarkRef>, ()>
[src]
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<PkgBodyRef, &'ctx Scope> 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<CtxItemsRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(
&self,
id: CtxItemsRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
[src]
&self,
id: CtxItemsRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<LibRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(
&self,
id: LibRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
[src]
&self,
id: LibRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubprogDeclRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(
&self,
id: SubprogDeclRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
[src]
&self,
id: SubprogDeclRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubtypeDeclRef, &'ctx Ty> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ProcessStmtRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(
&self,
id: ProcessStmtRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
[src]
&self,
id: ProcessStmtRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubprogBodyRef, &'ctx SubprogBody> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(&self, id: SubprogBodyRef) -> Result<&'ctx SubprogBody, ()>
[src]
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<LibRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ArchRef, DefValueRef> 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<IntfVarRef, &'ctx Ty> 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<SubprogBodyRef, &'ctx Scope> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<PkgBodyRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(
&self,
id: PkgBodyRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
[src]
&self,
id: PkgBodyRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<TypedNodeRef, &'ctx Ty> 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<ExprRef, &'ctx Const> 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<SubprogDeclRef, &'ctx Subprog> 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<PkgDeclRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(
&self,
_id: PkgDeclRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
[src]
&self,
_id: PkgDeclRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<LatentTypeMarkRef, &'ctx Ty> 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<ArchRef, DeclValueRef> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<ScopeRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(
&self,
id: ScopeRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
[src]
&self,
id: ScopeRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<EntityRef, &'ctx Entity> 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<ProcessStmtRef, &'ctx Scope> 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<SubprogBodyRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(
&self,
id: SubprogBodyRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
[src]
&self,
id: SubprogBodyRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubtypeDeclRef, &'ctx SubtypeDecl> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(&self, id: SubtypeDeclRef) -> Result<&'ctx SubtypeDecl, ()>
[src]
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<EntityRef, &'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(
&self,
_id: EntityRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
[src]
&self,
_id: EntityRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<PkgInstRef, &'ctx PackageInst> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(&self, id: PkgInstRef) -> Result<&'ctx PackageInst, ()>
[src]
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<SubprogInstRef, &'ctx SubprogInst> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(&self, id: SubprogInstRef) -> Result<&'ctx SubprogInst, ()>
[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 HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(
&self,
id: ArchRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
[src]
&self,
id: ArchRef
) -> Result<&'ctx HashMap<ResolvableName, Vec<Spanned<Def>>, RandomState>, ()>
impl<'lazy, 'sb, 'ast, 'ctx> NodeMaker<IntfFileRef, &'ctx Ty> 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<ArrayTypeIndexRef, &'ctx Spanned<ArrayTypeIndex>> for ScoreContext<'lazy, 'sb, 'ast, 'ctx>
[src]
fn make(
&self,
id: ArrayTypeIndexRef
) -> Result<&'ctx Spanned<ArrayTypeIndex>, ()>
[src]
&self,
id: ArrayTypeIndexRef
) -> Result<&'ctx Spanned<ArrayTypeIndex>, ()>