pub struct BuildContext { /* private fields */ }Expand description
What the compiler tells a node factory about the node it is building: the bindings under construction when the node was asked for, and the program tree’s resource scope.
Every factory receives one (crate::dsl::registry::NodeBuildFn).
A factory that records attribution reads Self::binding:
rate_adj := control_set("rate", target) builds control_set with
binding() equal to Some("rate_adj"). A node built inside another
binding’s construction sees the whole chain in Self::bindings,
outermost first: an argument that is itself a call compiles as an
intermediate binding the compiler names after its enclosing one
(x := f(control_set("r", t)) builds control_set under
["x", "x__anon_0"]), and a module body’s bindings compile under the
binding that called the module. The context is a value the compiler
hands down, so attribution is exact under nesting and on any thread.
A node that looks up a host resource when it evaluates keeps a clone
of Self::resources (resource.rs).
A #[polydat_node] node reads the context through a setup that
names ctx first, #[poly_const(setup, from = (ctx, key))], whose
function takes &BuildContext and returns what the node keeps;
the macro’s new() then takes the context as its first argument.
A caller building such a node directly passes
BuildContext::with_binding or BuildContext::new.
Implementations§
Source§impl BuildContext
impl BuildContext
Sourcepub fn new(bindings: Vec<String>, resources: ResourceScope) -> Self
pub fn new(bindings: Vec<String>, resources: ResourceScope) -> Self
A context for a node built under bindings (outermost first) in
the program tree whose resource scope is resources.
Sourcepub fn with_binding(name: impl Into<String>) -> Self
pub fn with_binding(name: impl Into<String>) -> Self
A context for a node built by the binding name alone, in a
tree of its own with no accessor installed: what a host’s test
passes to build a node that records its binding.
Sourcepub fn binding(&self) -> Option<&str>
pub fn binding(&self) -> Option<&str>
The binding whose construction built the node: the innermost of
Self::bindings. None for a node built outside any binding,
such as one a caller builds directly with build_node.
Sourcepub fn bindings(&self) -> &[String]
pub fn bindings(&self) -> &[String]
Every binding under construction when the node was built, outermost first.
Sourcepub fn resources(&self) -> &ResourceScope
pub fn resources(&self) -> &ResourceScope
The resource scope of the program tree the node belongs to.
Trait Implementations§
Source§impl Clone for BuildContext
impl Clone for BuildContext
Source§impl Debug for BuildContext
impl Debug for BuildContext
Auto Trait Implementations§
impl !RefUnwindSafe for BuildContext
impl !UnwindSafe for BuildContext
impl Freeze for BuildContext
impl Send for BuildContext
impl Sync for BuildContext
impl Unpin for BuildContext
impl UnsafeUnpin for BuildContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more