Skip to main content

Pdu

Struct Pdu 

Source
pub struct Pdu {
Show 14 fields pub kind: TimelineEventType, pub content: Content, pub event_id: OwnedEventId, pub room_id: OwnedRoomId, pub sender: OwnedUserId, pub state_key: Option<StateKey>, pub redacts: Option<OwnedEventId>, pub prev_events: PrevEvents, pub auth_events: AuthEvents, pub origin_server_ts: UInt, pub depth: UInt, pub hashes: EventHash, pub origin: Option<OwnedServerName>, pub unsigned: Option<Unsigned>,
}
Expand description

Stores a Matrix persistent data unit in typed form.

The representation retains canonical event fields used by state resolution, storage, and client serialization. Federation adapters normalize version-specific wire shapes.

Fields§

§kind: TimelineEventType

Matrix event type.

The value is serialized under the top-level type field.

§content: Content

Raw canonical event content.

Content remains encoded until a caller requests a typed or JSON value.

§event_id: OwnedEventId

Matrix identifier assigned to this event.

Stored PDUs always carry an owned event ID, including room versions that derive it outside the federation wire object.

§room_id: OwnedRoomId

Matrix room containing this event.

Stored PDUs carry the room ID even when a room version omits it from a creation event’s federation representation.

§sender: OwnedUserId

Matrix user who sent the event.

The sender participates in authorization and client-visible event output.

§state_key: Option<StateKey>

State key when this is a state event.

Message-like events store None and omit the field during serialization.

§redacts: Option<OwnedEventId>

Event targeted by a redaction when carried at the top level.

Newer room versions can place this value in event content instead. An absent target is omitted during serialization.

§prev_events: PrevEvents

Events declared as direct predecessors of this event.

The sequence is stored inline for the common single-predecessor case.

§auth_events: AuthEvents

Events used to authorize this event.

These identifiers form the event’s explicit authorization dependency set.

§origin_server_ts: UInt

Millisecond timestamp supplied by the originating server.

The value is preserved for ordering metadata and client serialization.

§depth: UInt

Event depth in the room directed acyclic graph.

Depth is originating-server-provided graph metadata and is distinct from the local timeline sequence.

§hashes: EventHash

Content hash declared by the event.

Federation validation compares the declaration with the computed content hash to detect content changes.

§origin: Option<OwnedServerName>

Server that originated an event carrying a top-level origin field.

Legacy event formats retain this value for local and remote events. The field is absent when it was not carried by the event format.

§unsigned: Option<Unsigned>

Unsigned metadata excluded from event hashing and signing.

Stored values are local annotations such as transaction IDs, age, prior state, and bundled relations. The field is omitted when absent.

Implementations§

Source§

impl Pdu

Source

pub fn remove_transaction_id(&mut self) -> Result

Removes the local transaction ID from unsigned event metadata.

Other unsigned properties are retained and the object is re-encoded. An event without unsigned data is left unchanged.

Source§

impl Pdu

Source

pub fn remove_prev_state(&mut self) -> Result

State-section serving strips the stored prev_content/prev_sender pair, dropping unsigned entirely when emptied; timeline serving keeps the trio.

Source§

impl Pdu

Source

pub fn add_age(&mut self) -> Result

Adds the event’s current age to unsigned metadata.

Age is the saturating millisecond difference between the current time and origin_server_ts. Future timestamps can therefore produce a negative value.

Source§

impl Pdu

Source

pub fn add_membership(&mut self, membership: &MembershipState) -> Result

MSC4115: annotate the served event with the requesting user’s room membership at the time of the event.

Source§

impl Pdu

Source

pub fn add_relation(&mut self, name: &str, pdu: Option<&Pdu>) -> Result

Adds or replaces a named bundled relation in unsigned metadata.

The related PDU is serialized under unsigned.m.relations; None stores an empty object for the named relation. Existing unsigned properties are retained.

Source§

impl Pdu

Source

pub fn set_thread_participated(&mut self, participated: bool) -> Result

MSC3816: overwrite unsigned.m.relations.m.thread.current_user_participated with a per-requester value. No-op when the event carries no thread bundle.

Source§

impl Pdu

Source

pub fn thread_latest_event(&self) -> Option<(OwnedEventId, OwnedUserId)>

MSC4025: identify the bundled m.thread latest_event without parsing the whole bundle: the sender keys the erasure gate, the event_id loads the event on a hit.

Source§

impl Pdu

Source

pub fn set_thread_latest_event( &mut self, latest: &Raw<AnySyncMessageLikeEvent>, ) -> Result

MSC4025: overwrite unsigned.m.relations.m.thread.latest_event, serving the pruned form of an erased sender’s thread activity. No-op when the event carries no thread bundle.

Source§

impl Pdu

Source

pub fn set_thread_count(&mut self, count: usize) -> Result

MSC3856: overwrite unsigned.m.relations.m.thread.count with a per-requester value excluding ignored senders’ replies. No-op when the event carries no thread bundle.

Source§

impl Pdu

Source

pub fn set_replacement_bundle( &mut self, replacement: &Raw<AnySyncMessageLikeEvent>, ) -> Result

MSC3925: fold the newest m.replace edit into unsigned.m.relations.m.replace as the full replacement event, preserving an existing bundle such as m.thread and creating unsigned when absent.

Source§

impl Pdu

Source

pub fn remove_replacement_bundle(&mut self) -> Result

Inverse of set_replacement_bundle: excise m.replace from unsigned.m.relations, dropping m.relations when the excision empties it and unsigned when that leaves nothing.

Source§

impl Pdu

Source

pub fn set_reference_bundle(&mut self, event_ids: &[OwnedEventId]) -> Result

MSC2675/MSC3267: fold reference relations into unsigned.m.relations.m.reference as { chunk: [{ event_id }, ...] }, preserving an existing bundle such as m.thread or m.replace and creating unsigned when absent.

Source§

impl Pdu

Source

pub fn from_object_and_roomid_and_eventid( room_id: &RoomId, event_id: &EventId, json: CanonicalJsonObject, ) -> Result<Self>

Inserts room and event IDs before deserializing a canonical PDU object.

Existing values under those keys are replaced. The resulting typed PDU owns both supplied identifiers.

Source

pub fn from_object_and_eventid( event_id: &EventId, json: CanonicalJsonObject, ) -> Result<Self>

Inserts an event ID before deserializing a canonical PDU object.

Any existing event_id value is replaced. Other object fields pass through to normal PDU deserialization.

Source

pub fn from_object_federation( room_id: &RoomId, event_id: &EventId, json: CanonicalJsonObject, rules: &RoomVersionRules, ) -> Result<(Self, CanonicalJsonObject)>

Normalizes federation wire fields and validates PDU format and room ID.

Version-specific wire fields are converted to the stored representation before these checks. Signature, content-hash, and authorization validation remain the caller’s responsibility.

§Panics

Panics if the object lacks type while the selected rules do not require a create-event room ID.

Source

pub fn from_object_checked( json: CanonicalJsonObject, rules: &RoomVersionRules, ) -> Result<Self>

Validates a canonical PDU object before deserializing it.

Checks use the supplied room-version event-format rules. Successful validation returns the typed stored representation.

Source

pub fn from_object(json: CanonicalJsonObject) -> Result<Self>

Deserializes a canonical JSON object into a stored PDU.

The object is wrapped as a canonical JSON value before typed deserialization. No room-version format checks are performed.

Source

pub fn from_raw_value(json: &RawJsonValue) -> Result<Self>

Deserializes raw JSON through a canonical JSON value.

Canonical conversion normalizes integer and object representation before the PDU fields are decoded. No room-version format checks are performed.

§Panics

Panics if the raw JSON contains a value outside canonical JSON, such as a floating-point value or an integer outside the canonical range.

Source

pub fn from_value(json: CanonicalJsonValue) -> Result<Self>

Deserializes a canonical JSON value into a stored PDU.

The input must contain the fields required by Pdu. No room-version format checks are performed before deserialization.

Source

pub fn from_raw_json(json: &RawJsonValue) -> Result<Self>

Deserializes raw JSON directly into a stored PDU.

This path uses Pdu’s Serde representation without first canonicalizing the input. Callers that require canonical validation should use a checked constructor.

Source

pub fn redacted(&self, rules: &RedactionRules) -> Result<Self>

MSC4025: a pruned clone per the redaction rules, carrying no redacted_because; no redaction event exists for a serve-time erasure.

Trait Implementations§

Source§

impl Clone for Pdu

Source§

fn clone(&self) -> Pdu

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Pdu

Source§

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

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

impl<'de> Deserialize<'de> for Pdu

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 Eq for Pdu

Prevent derived equality which wouldn’t limit itself to event_id

Source§

impl Event for Pdu
where Self: Send + Sync + 'static,

Source§

fn auth_events( &self, ) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_

All the authenticating events for this event.
Source§

fn auth_events_into( self, ) -> impl IntoIterator<IntoIter = impl Iterator<Item = OwnedEventId>> + Send

All the authenticating events for this event.
Source§

fn content(&self) -> &RawJsonValue

The event’s content.
Source§

fn event_id(&self) -> &EventId

The EventId of this event.
Source§

fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch

The time of creation on the originating server.
Source§

fn prev_events( &self, ) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_

The events before this event.
Source§

fn redacts(&self) -> Option<&EventId>

If this event is a redaction event this is the event it redacts.
Source§

fn rejected(&self) -> bool

Source§

fn room_id(&self) -> &RoomId

The RoomId of this event.
Source§

fn sender(&self) -> &UserId

The UserId of this event.
Source§

fn state_key(&self) -> Option<&str>

The state key for this event.
Source§

fn kind(&self) -> &TimelineEventType

The event type.
Source§

fn unsigned(&self) -> Option<&RawJsonValue>

Metadata container; peer-trusted only.
Source§

fn as_mut_pdu(&mut self) -> &mut Pdu

Returns mutable access to the common PDU representation. Read more
Source§

fn as_pdu(&self) -> &Pdu

Borrows the event as the common PDU representation. Read more
Source§

fn into_pdu(self) -> Pdu

Converts the event into an owned common PDU representation. Read more
Source§

fn is_owned(&self) -> bool

Reports whether consuming conversion can move an owned PDU. Read more
Source§

fn is_type_and_state_key( &self, kind: &TimelineEventType, state_key: &str, ) -> bool

Checks whether this event has both the requested type and state key. Read more
Source§

fn into_format<T>(self) -> T
where T: From<Owned<Self>>, Self: Sized,

Serialize into a Ruma JSON format, consuming.
Source§

fn to_format<'a, T>(&'a self) -> T
where T: From<Ref<'a, Self>>, Self: Sized + 'a,

Serialize into a Ruma JSON format
Source§

fn contains_unsigned_property<T>(&self, property: &str, is_type: T) -> bool
where T: FnOnce(&JsonValue) -> bool, Self: Sized,

Checks an unsigned-data property with a caller-supplied predicate. Read more
Source§

fn get_unsigned_property<T>(&self, property: &str) -> Result<T>
where T: for<'de> Deserialize<'de>, Self: Sized,

Deserializes one property from the event’s unsigned data. Read more
Source§

fn get_unsigned_as_value(&self) -> JsonValue
where Self: Sized,

Deserializes the event’s unsigned data as a JSON value. Read more
Source§

fn get_unsigned<T>(&self) -> Result<T>
where T: for<'de> Deserialize<'de>, Self: Sized,

Deserializes the complete unsigned-data object into a requested type. Read more
Source§

fn get_content_as_value(&self) -> JsonValue
where Self: Sized,

Deserializes event content as an untyped JSON value. Read more
Source§

fn get_content<T>(&self) -> Result<T>
where for<'de> T: Deserialize<'de>, Self: Sized,

Deserializes event content into a requested type. Read more
Source§

fn redacts_id(&self, room_rules: &RoomVersionRules) -> Option<OwnedEventId>
where Self: Sized,

Resolves the event ID targeted by a redaction event. Read more
Source§

fn is_redacted(&self) -> bool
where Self: Sized,

Reports whether the event carries redaction metadata. Read more
Source§

fn into_canonical_object(self) -> CanonicalJsonObject
where Self: Sized,

Consumes the event and serializes its PDU as a canonical JSON object. Read more
Source§

fn to_canonical_object(&self) -> CanonicalJsonObject

Serializes the event’s PDU as an owned canonical JSON object. Read more
Source§

fn into_value(self) -> JsonValue
where Self: Sized,

Consumes the event and serializes its PDU as a JSON value. Read more
Source§

fn to_value(&self) -> JsonValue

Serializes the event’s PDU as an owned JSON value. Read more
Source§

fn event_type(&self) -> &TimelineEventType

Returns the event’s timeline type. Read more
Source§

impl Event for &Pdu
where Self: Send,

Source§

fn auth_events( &self, ) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_

All the authenticating events for this event.
Source§

fn auth_events_into( self, ) -> impl IntoIterator<IntoIter = impl Iterator<Item = OwnedEventId>> + Send

All the authenticating events for this event.
Source§

fn content(&self) -> &RawJsonValue

The event’s content.
Source§

fn event_id(&self) -> &EventId

The EventId of this event.
Source§

fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch

The time of creation on the originating server.
Source§

fn prev_events( &self, ) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_

The events before this event.
Source§

fn redacts(&self) -> Option<&EventId>

If this event is a redaction event this is the event it redacts.
Source§

fn rejected(&self) -> bool

Source§

fn room_id(&self) -> &RoomId

The RoomId of this event.
Source§

fn sender(&self) -> &UserId

The UserId of this event.
Source§

fn state_key(&self) -> Option<&str>

The state key for this event.
Source§

fn kind(&self) -> &TimelineEventType

The event type.
Source§

fn unsigned(&self) -> Option<&RawJsonValue>

Metadata container; peer-trusted only.
Source§

fn as_pdu(&self) -> &Pdu

Borrows the event as the common PDU representation. Read more
Source§

fn into_pdu(self) -> Pdu

Converts the event into an owned common PDU representation. Read more
Source§

fn is_owned(&self) -> bool

Reports whether consuming conversion can move an owned PDU. Read more
Source§

fn is_type_and_state_key( &self, kind: &TimelineEventType, state_key: &str, ) -> bool

Checks whether this event has both the requested type and state key. Read more
Source§

fn into_format<T>(self) -> T
where T: From<Owned<Self>>, Self: Sized,

Serialize into a Ruma JSON format, consuming.
Source§

fn to_format<'a, T>(&'a self) -> T
where T: From<Ref<'a, Self>>, Self: Sized + 'a,

Serialize into a Ruma JSON format
Source§

fn contains_unsigned_property<T>(&self, property: &str, is_type: T) -> bool
where T: FnOnce(&JsonValue) -> bool, Self: Sized,

Checks an unsigned-data property with a caller-supplied predicate. Read more
Source§

fn get_unsigned_property<T>(&self, property: &str) -> Result<T>
where T: for<'de> Deserialize<'de>, Self: Sized,

Deserializes one property from the event’s unsigned data. Read more
Source§

fn get_unsigned_as_value(&self) -> JsonValue
where Self: Sized,

Deserializes the event’s unsigned data as a JSON value. Read more
Source§

fn get_unsigned<T>(&self) -> Result<T>
where T: for<'de> Deserialize<'de>, Self: Sized,

Deserializes the complete unsigned-data object into a requested type. Read more
Source§

fn get_content_as_value(&self) -> JsonValue
where Self: Sized,

Deserializes event content as an untyped JSON value. Read more
Source§

fn get_content<T>(&self) -> Result<T>
where for<'de> T: Deserialize<'de>, Self: Sized,

Deserializes event content into a requested type. Read more
Source§

fn redacts_id(&self, room_rules: &RoomVersionRules) -> Option<OwnedEventId>
where Self: Sized,

Resolves the event ID targeted by a redaction event. Read more
Source§

fn is_redacted(&self) -> bool
where Self: Sized,

Reports whether the event carries redaction metadata. Read more
Source§

fn into_canonical_object(self) -> CanonicalJsonObject
where Self: Sized,

Consumes the event and serializes its PDU as a canonical JSON object. Read more
Source§

fn to_canonical_object(&self) -> CanonicalJsonObject

Serializes the event’s PDU as an owned canonical JSON object. Read more
Source§

fn into_value(self) -> JsonValue
where Self: Sized,

Consumes the event and serializes its PDU as a JSON value. Read more
Source§

fn to_value(&self) -> JsonValue

Serializes the event’s PDU as an owned JSON value. Read more
Source§

fn as_mut_pdu(&mut self) -> &mut Pdu

Returns mutable access to the common PDU representation. Read more
Source§

fn event_type(&self) -> &TimelineEventType

Returns the event’s timeline type. Read more
Source§

impl Ord for Pdu

Ordering determined by the Pdu’s ID, not the memory representations.

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Pdu

Equality determined by the Pdu’s ID, not the memory representations.

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Pdu

Ordering determined by the Pdu’s ID, not the memory representations.

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Pdu

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

Auto Trait Implementations§

§

impl Freeze for Pdu

§

impl RefUnwindSafe for Pdu

§

impl Send for Pdu

§

impl Sync for Pdu

§

impl Unpin for Pdu

§

impl UnsafeUnpin for Pdu

§

impl UnwindSafe for Pdu

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

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

§

impl<T> DropFlavorWrapper<T> for T

§

type Flavor = MayDrop

The DropFlavor that [wrap]s T into Self
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ExpectInto for T

Source§

fn expect_into<Dst: TryFrom<Self>>(self) -> Dst
where Self: Sized,

Converts the value into Dst and returns the successful result. Read more
Source§

impl<T> Expected for T

Source§

fn expected_add(self, rhs: Self) -> Self
where Self: CheckedAdd + Sized,

Adds rhs with an expectation that the operation is valid. Read more
Source§

fn expected_sub(self, rhs: Self) -> Self
where Self: CheckedSub + Sized,

Subtracts rhs with an expectation that the operation is valid. Read more
Source§

fn expected_mul(self, rhs: Self) -> Self
where Self: CheckedMul + Sized,

Multiplies by rhs with an expectation that the operation is valid. Read more
Source§

fn expected_div(self, rhs: Self) -> Self
where Self: CheckedDiv + Sized,

Divides by rhs with an expectation that the operation is valid. Read more
Source§

fn expected_rem(self, rhs: Self) -> Self
where Self: CheckedRem + Sized,

Computes the remainder with an expectation that the operation is valid. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

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

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
§

impl<T> JsonCastable<CanonicalJsonValue> for T

§

impl<T> JsonCastable<Value> for T

§

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

§

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();
§

fn primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Primary].

§Example
println!("{}", value.primary());
§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Fixed].

§Example
println!("{}", value.fixed(color));
§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Rgb].

§Example
println!("{}", value.rgb(r, g, b));
§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Black].

§Example
println!("{}", value.black());
§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Red].

§Example
println!("{}", value.red());
§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Green].

§Example
println!("{}", value.green());
§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Yellow].

§Example
println!("{}", value.yellow());
§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Blue].

§Example
println!("{}", value.blue());
§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Magenta].

§Example
println!("{}", value.magenta());
§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Cyan].

§Example
println!("{}", value.cyan());
§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: White].

§Example
println!("{}", value.white());
§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlack].

§Example
println!("{}", value.bright_black());
§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightRed].

§Example
println!("{}", value.bright_red());
§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightGreen].

§Example
println!("{}", value.bright_green());
§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightYellow].

§Example
println!("{}", value.bright_yellow());
§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlue].

§Example
println!("{}", value.bright_blue());
§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.bright_magenta());
§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightCyan].

§Example
println!("{}", value.bright_cyan());
§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightWhite].

§Example
println!("{}", value.bright_white());
§

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();
§

fn on_primary(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Primary].

§Example
println!("{}", value.on_primary());
§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Fixed].

§Example
println!("{}", value.on_fixed(color));
§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Black].

§Example
println!("{}", value.on_black());
§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Red].

§Example
println!("{}", value.on_red());
§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Green].

§Example
println!("{}", value.on_green());
§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Yellow].

§Example
println!("{}", value.on_yellow());
§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Blue].

§Example
println!("{}", value.on_blue());
§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Magenta].

§Example
println!("{}", value.on_magenta());
§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Cyan].

§Example
println!("{}", value.on_cyan());
§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: White].

§Example
println!("{}", value.on_white());
§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlack].

§Example
println!("{}", value.on_bright_black());
§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightRed].

§Example
println!("{}", value.on_bright_red());
§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightGreen].

§Example
println!("{}", value.on_bright_green());
§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlue].

§Example
println!("{}", value.on_bright_blue());
§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightWhite].

§Example
println!("{}", value.on_bright_white());
§

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();
§

fn bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Bold].

§Example
println!("{}", value.bold());
§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Dim].

§Example
println!("{}", value.dim());
§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Italic].

§Example
println!("{}", value.italic());
§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute :: Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute :: RapidBlink].

§Example
println!("{}", value.rapid_blink());
§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Invert].

§Example
println!("{}", value.invert());
§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Conceal].

§Example
println!("{}", value.conceal());
§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Strike].

§Example
println!("{}", value.strike());
§

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();
§

fn mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Mask].

§Example
println!("{}", value.mask());
§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Wrap].

§Example
println!("{}", value.wrap());
§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Linger].

§Example
println!("{}", value.linger());
§

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.

Returns self with the quirk() set to [Quirk :: Clear].

§Example
println!("{}", value.clear());
§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Resetting].

§Example
println!("{}", value.resetting());
§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Bright].

§Example
println!("{}", value.bright());
§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: OnBright].

§Example
println!("{}", value.on_bright());
§

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

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new [Painted] with a default [Style]. Read more
§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn add_extension<T>(self, value: T) -> AddExtension<Self, T>
where Self: Sized,

Add some shareable value to request extensions. Read more
§

fn compression(self) -> Compression<Self>
where Self: Sized,

Compresses response bodies. Read more
§

fn decompression(self) -> Decompression<Self>
where Self: Sized,

Decompress response bodies. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
§

fn sensitive_headers( self, headers: impl IntoIterator<Item = HeaderName>, ) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>
where Self: Sized,

Mark headers as sensitive on both requests and responses. Read more
§

fn sensitive_request_headers( self, headers: impl IntoIterator<Item = HeaderName>, ) -> SetSensitiveRequestHeaders<Self>
where Self: Sized,

Mark headers as sensitive on requests. Read more
§

fn sensitive_response_headers( self, headers: impl IntoIterator<Item = HeaderName>, ) -> SetSensitiveResponseHeaders<Self>
where Self: Sized,

Mark headers as sensitive on responses. Read more
§

fn override_request_header<M>( self, header_name: HeaderName, make: M, ) -> SetRequestHeader<Self, M>
where Self: Sized,

Insert a header into the request. Read more
§

fn append_request_header<M>( self, header_name: HeaderName, make: M, ) -> SetRequestHeader<Self, M>
where Self: Sized,

Append a header into the request. Read more
§

fn insert_request_header_if_not_present<M>( self, header_name: HeaderName, make: M, ) -> SetRequestHeader<Self, M>
where Self: Sized,

Insert a header into the request, if the header is not already present. Read more
§

fn override_response_header<M>( self, header_name: HeaderName, make: M, ) -> SetResponseHeader<Self, M>
where Self: Sized,

Insert a header into the response. Read more
§

fn append_response_header<M>( self, header_name: HeaderName, make: M, ) -> SetResponseHeader<Self, M>
where Self: Sized,

Append a header into the response. Read more
§

fn insert_response_header_if_not_present<M>( self, header_name: HeaderName, make: M, ) -> SetResponseHeader<Self, M>
where Self: Sized,

Insert a header into the response, if the header is not already present. Read more
§

fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>
where Self: Sized,

Catch panics and convert them into 500 Internal Server responses. Read more
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> Tried for T

Source§

fn try_add(self, rhs: Self) -> Result<Self>
where Self: CheckedAdd + Sized,

Adds rhs with checked arithmetic. Read more
Source§

fn try_sub(self, rhs: Self) -> Result<Self>
where Self: CheckedSub + Sized,

Subtracts rhs with checked arithmetic. Read more
Source§

fn try_mul(self, rhs: Self) -> Result<Self>
where Self: CheckedMul + Sized,

Multiplies by rhs with checked arithmetic. Read more
Source§

fn try_div(self, rhs: Self) -> Result<Self>
where Self: CheckedDiv + Sized,

Divides by rhs with checked arithmetic. Read more
Source§

fn try_rem(self, rhs: Self) -> Result<Self>
where Self: CheckedRem + Sized,

Computes the remainder by rhs with checked arithmetic. 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more