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 ReadVars 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>

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>
where T: 'static, U: Serialize + DeserializeOwned + 'static, F: FnOnce(T) -> U + 'static,

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, )
where T: 'static, U: Serialize + DeserializeOwned + 'static, F: FnOnce(T) -> U + 'static,

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,

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,

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>

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,

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,

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<'_>)

Consume this ReadVar outside the context of a step, signalling that it won’t be used.

Trait Implementations§

§

impl<T> ClaimVar for ReadVar<T>

§

type Claimed = ReadVar<T, VarClaimed>

The claimed version of Self.
§

fn claim(self, ctx: &mut StepCtx<'_>) -> ReadVar<T, VarClaimed>

Claim the Var for this step, allowing it to be accessed at runtime.
§

impl<T, C> Clone for ReadVar<T, C>

§

fn clone(&self) -> ReadVar<T, C>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<T, C> Debug for ReadVar<T, C>
where T: Debug, C: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'de, T, C> Deserialize<'de> for ReadVar<T, C>
where T: Deserialize<'de>,

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ReadVar<T, C>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl From<ReadVar<String>> for GhParam

§

fn from(param: ReadVar<String>) -> GhParam

Converts to this type from the input type.
§

impl<T> ReadVarValue for ReadVar<T, VarClaimed>

§

type Value = T

The read value of Self.
§

fn read_value( self, rt: &mut RustRuntimeServices<'_>, ) -> <ReadVar<T, VarClaimed> as ReadVarValue>::Value

Read the value of the Var at runtime.
§

impl<T, C> Serialize for ReadVar<T, C>
where T: Serialize,

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl<T> VarEqBacking for ReadVar<T>

§

fn eq(&self, other: &ReadVar<T>) -> bool

Check if self is backed by the same variable as other.

Auto Trait Implementations§

§

impl<T, C> Freeze for ReadVar<T, C>
where T: Freeze,

§

impl<T, C> RefUnwindSafe for ReadVar<T, C>

§

impl<T, C> Send for ReadVar<T, C>
where T: Send, C: Send,

§

impl<T, C> Sync for ReadVar<T, C>
where T: Sync, C: Sync,

§

impl<T, C> Unpin for ReadVar<T, C>
where T: Unpin, C: Unpin,

§

impl<T, C> UnwindSafe for ReadVar<T, C>
where T: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,