pub struct ReadVar<T: Serialize + DeserializeOwned, C = VarNotClaimed> { /* private fields */ }
Expand description
Read a value from a flowey Var at runtime, returning the value written by
the Var’s corresponding WriteVar
.
Vars in flowey must be serde de/serializable, in order to be de/serialized between multiple steps/nodes.
In order to read the value contained within a ReadVar
, it must first be
claimed by a particular step (using the ClaimVar::claim
API). Once
claimed, the Var can be read using APIs such as
RustRuntimeServices::read
, or AdoStepServices::get_var
Note that all ReadVar
s in flowey are immutable. In other words:
reading the value of a ReadVar
multiple times from multiple nodes will
always return the same value.
This is a natural consequence ReadVar
obtaining its value from the result
of a write into WriteVar
, whose API enforces that there can only ever be
a single Write to a WriteVar
.
Implementations§
Source§impl<T: Serialize + DeserializeOwned> ReadVar<T>
impl<T: Serialize + DeserializeOwned> ReadVar<T>
Sourcepub fn into_side_effect(self) -> ReadVar<SideEffect>
pub fn into_side_effect(self) -> ReadVar<SideEffect>
Discard any type information associated with the Var, and treat the Var as through it was only a side effect.
e.g: if a Node returns a ReadVar<PathBuf>
, but you know that the mere
act of having run the node has ensured the file is placed in a “magic
location” for some other node, then it may be useful to treat the
ReadVar<PathBuf>
as a simple ReadVar<SideEffect>
, which can be
passed along as part of a larger bundle of Vec<ReadVar<SideEffect>>
.
Sourcepub fn map<F, U>(&self, ctx: &mut NodeCtx<'_>, f: F) -> ReadVar<U>
pub fn map<F, U>(&self, ctx: &mut NodeCtx<'_>, f: F) -> ReadVar<U>
Maps a ReadVar<T>
to a new ReadVar<U>
, by applying a function to the
Var at runtime.
Sourcepub fn write_into<F, U>(
&self,
ctx: &mut NodeCtx<'_>,
write_into: WriteVar<U>,
f: F,
)
pub fn write_into<F, U>( &self, ctx: &mut NodeCtx<'_>, write_into: WriteVar<U>, f: F, )
Maps a ReadVar<T>
into an existing WriteVar<U>
by applying a
function to the Var at runtime.
Sourcepub fn zip<U>(
&self,
ctx: &mut NodeCtx<'_>,
other: ReadVar<U>,
) -> ReadVar<(T, U)>where
T: 'static,
U: Serialize + DeserializeOwned + 'static,
pub fn zip<U>(
&self,
ctx: &mut NodeCtx<'_>,
other: ReadVar<U>,
) -> ReadVar<(T, U)>where
T: 'static,
U: Serialize + DeserializeOwned + 'static,
Zips self (ReadVar<T>
) with another ReadVar<U>
, returning a new
ReadVar<(T, U)>
Sourcepub fn from_static(val: T) -> ReadVar<T>where
T: 'static,
pub fn from_static(val: T) -> ReadVar<T>where
T: 'static,
Create a new ReadVar
from a static value.
WARNING: Static vars CANNOT BE SECRETS, as they are encoded as plain-text in the output flow.
Sourcepub fn get_static(&self) -> Option<T>
pub fn get_static(&self) -> Option<T>
If this ReadVar
contains a static value, return it.
Nodes can opt-in to using this method as a way to generate optimized steps in cases where the value of a variable is known ahead of time.
e.g: a node doing a git checkout could leverage this method to decide whether its ADO backend should emit a conditional step for checking out a repo, or if it can statically include / exclude the checkout request.
Sourcepub fn transpose_vec(
ctx: &mut NodeCtx<'_>,
vec: Vec<ReadVar<T>>,
) -> ReadVar<Vec<T>>where
T: 'static,
pub fn transpose_vec(
ctx: &mut NodeCtx<'_>,
vec: Vec<ReadVar<T>>,
) -> ReadVar<Vec<T>>where
T: 'static,
Transpose a Vec<ReadVar<T>>
into a ReadVar<Vec<T>>
Sourcepub fn claim_unused(self, ctx: &mut NodeCtx<'_>)
pub fn claim_unused(self, ctx: &mut NodeCtx<'_>)
Consume this ReadVar
outside the context of a step, signalling that it
won’t be used.