pub struct AccountDelta { /* private fields */ }Expand description
The AccountDelta stores the differences between two account states, which can result from
one or more transaction.
The differences are represented as follows:
- storage: an
AccountStoragePatchthat contains the changes to the account storage. - vault: an
AccountVaultDeltaobject that contains the changes to the account vault. - nonce: if the nonce of the account has changed, the delta of the nonce is stored, i.e. the value by which the nonce increased.
- code: an
AccountCodefor new accounts andNonefor others.
The presence of the code in a delta signals if the delta is a full state or partial state
delta. A full state delta must be converted into an Account object, while a partial state
delta must be applied to an existing Account. Because a full state delta reconstructs the
account from empty storage, its storage patch may only create slots, never update or remove
them; AccountDelta::new enforces this.
TODO(code_upgrades): The ability to track account code updates is an outstanding feature. For that reason, the account code is not considered as part of the “nonce must be incremented if state changed” check.
Implementations§
Source§impl AccountDelta
impl AccountDelta
Sourcepub fn new(
account_id: AccountId,
storage: AccountStoragePatch,
vault: AccountVaultDelta,
code: Option<AccountCode>,
nonce_delta: Felt,
) -> Result<AccountDelta, AccountDeltaError>
pub fn new( account_id: AccountId, storage: AccountStoragePatch, vault: AccountVaultDelta, code: Option<AccountCode>, nonce_delta: Felt, ) -> Result<AccountDelta, AccountDeltaError>
Returns new AccountDelta instantiated from the provided components.
code is Some for a full state delta (a new account) and None otherwise.
§Errors
- Returns an error if storage or vault were updated, but the nonce_delta is 0.
- Returns an error if
codeis provided but the storage patch contains anUpdateorRemoveoperation. A full state delta must reconstruct the account from empty storage, so it may only create slots.
Sourcepub fn vault_mut(&mut self) -> &mut AccountVaultDelta
pub fn vault_mut(&mut self) -> &mut AccountVaultDelta
Returns a mutable reference to the account vault delta.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this account delta does not contain any vault, storage or nonce updates.
Sourcepub fn is_full_state(&self) -> bool
pub fn is_full_state(&self) -> bool
Returns true if this delta is a “full state” delta, false otherwise, i.e. if it is a
“partial state” delta.
See the type-level docs for more on this distinction.
Sourcepub fn storage(&self) -> &AccountStoragePatch
pub fn storage(&self) -> &AccountStoragePatch
Returns storage updates for this account delta.
Sourcepub fn vault(&self) -> &AccountVaultDelta
pub fn vault(&self) -> &AccountVaultDelta
Returns vault updates for this account delta.
Sourcepub fn nonce_delta(&self) -> Felt
pub fn nonce_delta(&self) -> Felt
Returns the amount by which the nonce was incremented.
Sourcepub fn code(&self) -> Option<&AccountCode>
pub fn code(&self) -> Option<&AccountCode>
Returns a reference to the account code of this delta, if present.
Sourcepub fn into_parts(
self,
) -> (AccountStoragePatch, AccountVaultDelta, Option<AccountCode>, Felt)
pub fn into_parts( self, ) -> (AccountStoragePatch, AccountVaultDelta, Option<AccountCode>, Felt)
Converts this delta into its individual components.
Sourcepub fn to_commitment(&self) -> Word
pub fn to_commitment(&self) -> Word
Computes the commitment to the account delta.
§Computation
The delta commitment is a sequential hash over a vector of field elements which starts out
empty and is appended to in the following way. Whenever sorting is expected, it is that
of a Word.
- Append
[[domain = 1, nonce_delta, account_id_suffix, account_id_prefix], EMPTY_WORD], whereaccount_id_{prefix,suffix}are the prefix and suffix felts of the native account id,nonce_deltais the value by which the nonce was incremented, anddomain = 1identifies the header as the start of an account delta commitment. - Asset Delta
- For each added asset, sorted by its asset ID:
- Append
[ASSET_ID, ASSET_VALUE].
- Append
- Append
[domain = 3, delta_op = 1, num_added_assets, 0]ifnum_added_assets != 0wherenum_added_assetsis the number of added assets anddelta_opis set to1indicating asset addition. - For each removed asset, sorted by its asset ID:
- Append
[ASSET_ID, ASSET_VALUE].
- Append
- Append
[domain = 3, delta_op = 2, num_removed_assets, 0]ifnum_removed_assets != 0wherenum_removed_assetsis the number of removed assets anddelta_opis set to2indicating asset removal. - Note that the domain is the same independent of asset addition or removal, since the
delta_opsufficiently distinguishes the two domains.
- For each added asset, sorted by its asset ID:
- Storage Slots are sorted by slot ID and are iterated in this order.
patch_opis theStoragePatchOperationof the slot patch andslot_id_{suffix, prefix}is the identifier of the slot. For each slot, depending on its slot type:- Value Slot
- Append
[[domain = 5, patch_op, slot_id_suffix, slot_id_prefix], NEW_VALUE]whereNEW_VALUEis the new value of the slot.
- Append
- Map Slot
- For each key-value pair, sorted by key, whose new value is different from the previous
value in the map:
- Append
[KEY, NEW_VALUE].
- Append
- The map trailer is constructed as
[[domain = 6, patch_op, slot_id_suffix, slot_id_prefix], [num_changed_entries, 0, 0, 0]], wherenum_changed_entriesis the number of key-value pairs appended above. Whether the trailer is included depends onpatch_op:- For
StoragePatchOperation::Create, the trailer is always included, since the slot’s creation must be committed to even when the map is created empty (num_changed_entries == 0). - For
StoragePatchOperation::Update, the trailer is included only ifnum_changed_entries != 0. An update that changes no entries is a no-op and is omitted entirely. - For
StoragePatchOperation::Remove, the trailer is always included withnum_changed_entriesset to zero, since the number of removed entries is unknown.
- For
- For each key-value pair, sorted by key, whose new value is different from the previous
value in the map:
- Value Slot
§Rationale
The rationale for this layout is that hashing in the VM should be as efficient as possible and minimize the number of branches to be as efficient as possible. Every high-level section in this bullet point list should add an even number of words since the hasher operates on double words. In the VM, each permutation is done immediately, so adding an uneven number of words in a given step will result in more difficulty in the MASM implementation.
§New Accounts
The delta for new accounts (a full state delta) must commit to all the created storage slots of the account, even if these slots contain the default value (e.g. the empty word for value slots or an empty storage map). This ensures the full state delta commits to the exact storage slots that are contained in the account.
§Security
The general concern with the commitment is that two distinct deltas must never hash to the same commitment. E.g. a commitment of a delta that changes a key-value pair in a storage map slot should be different from a delta that adds a non-fungible asset to the vault. If not, a delta can be crafted in the VM that sets a map key but a malicious actor crafts a delta outside the VM that adds a non-fungible asset. To prevent that, a couple of measures are taken.
- Because multiple unrelated domains (e.g. vaults and storage slots) are hashed in the same hasher, domain separators are used to disambiguate. For each changed asset and each changed slot in the delta, a domain separator is hashed into the delta. The domain separator is always at the same index in each layout so it cannot be maliciously crafted (see below for an example).
- Storage value slots:
- since value slots are only included in the patch if their value has changed when the
operation is
Update, there is no ambiguity between a value slot being set to EMPTY_WORD and its value being unchanged.
- since value slots are only included in the patch if their value has changed when the
operation is
- Storage map slots:
- Map slots append a header which summarizes the changes in the slot, in particular the slot ID and number of changed entries.
- Two distinct storage map slots use the same domain but are disambiguated due to inclusion of the slot ID.
§Domain Separators
As an example for ambiguity, consider these two deltas:
[
ID_AND_NONCE, EMPTY_WORD,
[ASSET_ID, ASSET_VALUE],
[[domain = 3, delta_op = 1, num_added_assets = 1, 0], EMPTY_WORD],
[/* no removed assets delta */],
[/* no storage patch */]
][
ID_AND_NONCE, EMPTY_WORD,
[/* no asset delta */],
[[domain = 5, patch_op, slot_id_suffix0, slot_id_prefix0], NEW_VALUE]
[[domain = 5, patch_op, slot_id_suffix1, slot_id_prefix1], NEW_VALUE]
]NEW_VALUEis user-controlled and can be crafted to matchASSET_VALUEorEMPTY_WORD.- Slot IDs are user-controlled and can be crafted to match the two most significant elements
in the asset ID or
num_added_assetsand the fixed 0. - This leaves only the domain separator and the patch_op to differentiate these two deltas.
The delta and patch headers further use distinct domain separators (1 and 2 respectively), so a delta and a patch with otherwise identical bodies can never collide.
§Number of Changed Entries
As an example for ambiguity, consider these two deltas:
[
ID_AND_NONCE, EMPTY_WORD,
[/* no asset delta */],
[domain = 6, patch_op, slot_id_suffix = 20, slot_id_prefix = 21, num_changed_entries = 0, 0, 0, 0]
[domain = 6, patch_op, slot_id_suffix = 42, slot_id_prefix = 43, num_changed_entries = 0, 0, 0, 0]
][
ID_AND_NONCE, EMPTY_WORD,
[/* no asset delta */],
[KEY0, VALUE0],
[domain = 6, patch_op, slot_id_suffix = 42, slot_id_prefix = 43, num_changed_entries = 1, 0, 0, 0]
]The keys and values of map slots are user-controllable so KEY0 and VALUE0 could be
crafted to match the first map header in the first delta. So, without having
num_changed_entries included in the commitment, these deltas would be ambiguous. A delta
with two empty maps could have the same commitment as a delta with one map entry where one
key-value pair has changed.
§New Accounts
The number of changed entries of a storage map can be validly zero when an empty storage map is created in account (e.g. at account creation time). In such cases, the number of changed key-value pairs is 0, but the map must still be committed to, in order to differentiate between a slot being created as an empty map or not being created at all.
Trait Implementations§
Source§impl Clone for AccountDelta
impl Clone for AccountDelta
Source§fn clone(&self) -> AccountDelta
fn clone(&self) -> AccountDelta
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AccountDelta
impl Debug for AccountDelta
Source§impl Deserializable for AccountDelta
impl Deserializable for AccountDelta
Source§fn read_from<R>(source: &mut R) -> Result<AccountDelta, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<AccountDelta, DeserializationError>where
R: ByteReader,
source, attempts to deserialize these bytes
into Self, and returns the result. Read moreSource§fn min_serialized_size() -> usize
fn min_serialized_size() -> usize
Source§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Source§fn read_from_bytes_with_budget(
bytes: &[u8],
budget: usize,
) -> Result<Self, DeserializationError>
fn read_from_bytes_with_budget( bytes: &[u8], budget: usize, ) -> Result<Self, DeserializationError>
Self from bytes with a byte budget limit. Read moreimpl Eq for AccountDelta
Source§impl PartialEq for AccountDelta
impl PartialEq for AccountDelta
Source§impl SequentialCommit for AccountDelta
impl SequentialCommit for AccountDelta
Source§fn to_elements(&self) -> Vec<Felt>
fn to_elements(&self) -> Vec<Felt>
Reduces the delta to a sequence of field elements.
See AccountDelta::to_commitment() for more details.
Source§type Commitment = Word
type Commitment = Word
Source§fn to_commitment(&self) -> Self::Commitment
fn to_commitment(&self) -> Self::Commitment
Source§impl Serializable for AccountDelta
impl Serializable for AccountDelta
Source§fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
self into bytes and writes these bytes into the target.Source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
impl StructuralPartialEq for AccountDelta
Source§impl TryFrom<&AccountDelta> for Account
impl TryFrom<&AccountDelta> for Account
Source§fn try_from(
delta: &AccountDelta,
) -> Result<Account, <Account as TryFrom<&AccountDelta>>::Error>
fn try_from( delta: &AccountDelta, ) -> Result<Account, <Account as TryFrom<&AccountDelta>>::Error>
Converts an AccountDelta into an Account.
Conceptually, this applies the delta onto an empty account.
§Errors
Returns an error if:
- If the delta is not a full state delta. See
AccountDeltafor details. - If any vault delta operation removes an asset.
- If any vault delta operation adds an asset that would overflow the maximum representable amount.
- If any storage patch update violates account storage constraints.
Source§type Error = AccountError
type Error = AccountError
Source§impl TryFrom<Account> for AccountDelta
impl TryFrom<Account> for AccountDelta
Source§fn try_from(
account: Account,
) -> Result<AccountDelta, <AccountDelta as TryFrom<Account>>::Error>
fn try_from( account: Account, ) -> Result<AccountDelta, <AccountDelta as TryFrom<Account>>::Error>
Converts an Account into an AccountDelta.
§Errors
Returns an error if:
- the account has a seed. Accounts with seeds have a nonce of 0. Representing such accounts as deltas is not possible because deltas with a non-empty state change need a nonce_delta greater than 0.
Source§type Error = AccountError
type Error = AccountError
Auto Trait Implementations§
impl Freeze for AccountDelta
impl RefUnwindSafe for AccountDelta
impl Send for AccountDelta
impl Sync for AccountDelta
impl Unpin for AccountDelta
impl UnsafeUnpin for AccountDelta
impl UnwindSafe for AccountDelta
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read moreSource§fn fg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
Source§fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
Source§fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
Source§fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
Source§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);