Struct ReadVar
pub struct ReadVar<T, 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§
§impl<T> ReadVar<T>where
T: Serialize + DeserializeOwned,
impl<T> ReadVar<T>where
T: Serialize + DeserializeOwned,
pub fn into_side_effect(self) -> ReadVar<()>
pub fn into_side_effect(self) -> ReadVar<()>
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>>
.
pub 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.
pub 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.
pub 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)>
pub 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 values CANNOT BE SECRETS, as they are encoded as plain-text in the output flow.
pub 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.
pub 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>>
pub fn depending_on<U>(
&self,
ctx: &mut NodeCtx<'_>,
other: &ReadVar<U>,
) -> ReadVar<T>where
T: 'static,
U: Serialize + DeserializeOwned + 'static,
pub fn depending_on<U>(
&self,
ctx: &mut NodeCtx<'_>,
other: &ReadVar<U>,
) -> ReadVar<T>where
T: 'static,
U: Serialize + DeserializeOwned + 'static,
Returns a new instance of this variable with an artificial dependency on
other
.
This is useful for making explicit a non-explicit dependency between the
two variables. For example, if self
contains a path to a file, and
other
is only written once that file has been created, then this
method can be used to return a new ReadVar
which depends on other
but is otherwise identical to self
. This ensures that when the new
variable is read, the file has been created.
In general, it is better to ensure that the dependency is explicit, so that if you have a variable with a path, then you know that the file exists when you read it. This method is useful in cases where this is not naturally the case, e.g., when you are providing a path as part of a request, as opposed to the path being returned to you.
pub 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.