Struct ReadVar

Source
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 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§

Source§

impl<T: Serialize + DeserializeOwned> ReadVar<T>

Source

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

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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

Source

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§

Source§

impl<T: Serialize + DeserializeOwned> ClaimVar for ReadVar<T>

Source§

type Claimed = ReadVar<T, VarClaimed>

The claimed version of Self.
Source§

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

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

impl<T: Serialize + DeserializeOwned, C> Clone for ReadVar<T, C>

Source§

fn clone(&self) -> Self

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
Source§

impl<T: Debug + Serialize + DeserializeOwned, C: Debug> Debug for ReadVar<T, C>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de, T: Serialize + DeserializeOwned, C> Deserialize<'de> for ReadVar<T, C>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl From<ReadVar<String>> for GhParam

Source§

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

Converts to this type from the input type.
Source§

impl<T: Serialize + DeserializeOwned, C> Serialize for ReadVar<T, C>

Source§

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

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

impl<T> VarEqBacking for ReadVar<T>

Source§

fn eq(&self, other: &Self) -> 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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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>,