pub struct Memo { /* private fields */ }Expand description
A view onto a MemoStore scoped to a (run_id, step_number)
pair, or to a run as a whole.
Implementations§
Source§impl Memo
impl Memo
Sourcepub fn step_number(&self) -> Option<u32>
pub fn step_number(&self) -> Option<u32>
The step number this memo is bound to; None for a run-scoped
memo.
Sourcepub async fn get(&self, key: &str) -> Result<Option<Vec<u8>>>
pub async fn get(&self, key: &str) -> Result<Option<Vec<u8>>>
Read a previously stored value for key, or Ok(None) if
none has been written.
Sourcepub async fn put(&self, key: &str, value: &[u8]) -> Result<()>
pub async fn put(&self, key: &str, value: &[u8]) -> Result<()>
Store value for key, overwriting any prior value.
Overwrite is intentional: a retry that produces the same value is idempotent. A retry that produces a different value indicates the handler isn’t perfectly idempotent; the memo reflects whatever the most recent attempt wrote.
Sourcepub async fn memoized<R, F, E>(&self, key: &str, compute: F) -> Result<R, E>
pub async fn memoized<R, F, E>(&self, key: &str, compute: F) -> Result<R, E>
Return the value stored under key, or run compute, store its
value under key and return it.
The value is encoded as MessagePack with named fields. An entry
that fails to decode as R is treated as absent: compute runs
and its value overwrites the entry. An error from compute is
returned without storing anything, so a later call runs compute
again.
A side effect inside compute runs again when the process terminates
after compute returns and before the value is stored.
Sourcepub async fn memoized_by_content<K, R, F, E>(
&self,
input: &K,
compute: F,
) -> Result<R, E>
pub async fn memoized_by_content<K, R, F, E>( &self, input: &K, compute: F, ) -> Result<R, E>
Self::memoized under Self::content_key of input.
Sourcepub fn content_key<T>(input: &T) -> Result<String>
pub fn content_key<T>(input: &T) -> Result<String>
Derive the memo key for a content-addressed entry: content:
followed by the hex SHA-256 digest of input encoded as
MessagePack with named fields.
The key is stable only when input serializes
deterministically; types with unordered iteration, such as
HashMap, can serialize the same logical content into different
bytes and therefore different keys. If several logical
operations may receive identical inputs, include an operation
name in the serialized input.
Sourcepub async fn content_get<T>(&self, input: &T) -> Result<Option<Vec<u8>>>
pub async fn content_get<T>(&self, input: &T) -> Result<Option<Vec<u8>>>
Read the memo entry stored under Self::content_key of
input.
Sourcepub async fn content_put<T>(&self, input: &T, value: &[u8]) -> Result<()>
pub async fn content_put<T>(&self, input: &T, value: &[u8]) -> Result<()>
Store value under Self::content_key of input.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Memo
impl !UnwindSafe for Memo
impl Freeze for Memo
impl Send for Memo
impl Sync for Memo
impl Unpin for Memo
impl UnsafeUnpin for Memo
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
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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);