Skip to main content

Service

Struct Service 

Source
pub struct Service {
    keypair: Box<Ed25519KeyPair>,
    verify_keys: VerifyKeys,
    minimum_valid: Duration,
    services: Arc<OnceServices>,
    db: Data,
}
Expand description

Manages the local signing identity and cached remote verification keys.

Cached keys are retained by key ID without enforcing valid_until_ts on reads. Missing keys can be acquired from remote origins or trusted notaries.

Fields§

§keypair: Box<Ed25519KeyPair>§verify_keys: VerifyKeys§minimum_valid: Duration§services: Arc<OnceServices>§db: Data

Implementations§

Source§

impl Service

Source

pub async fn acquire_events_pubkeys<'a, I>(&self, events: I)
where I: Iterator<Item = &'a Box<RawJsonValue>> + Send,

Acquires the signing keys referenced by a collection of raw events.

Signature maps are grouped and deduplicated before acquisition. Events with malformed JSON or unreadable signature fields are silently skipped.

Source§

impl Service

Source

pub async fn acquire_pubkeys<'a, S, K>(&self, batch: S)
where S: Iterator<Item = (&'a ServerName, K)> + Send + Clone, K: Iterator<Item = &'a ServerSigningKeyId> + Send + Clone,

Best-effort acquires a batch of server signing keys into the local cache.

Local storage is checked first, then origins and trusted notaries are tried according to configuration. The method returns no status; keys still missing after all allowed sources are logged.

Source§

impl Service

Source

async fn acquire_locals<'a, S, K>( &self, batch: S, ) -> BTreeMap<OwnedServerName, Vec<OwnedServerSigningKeyId>>
where S: Iterator<Item = (&'a ServerName, K)> + Send, K: Iterator<Item = &'a ServerSigningKeyId> + Send,

Source§

impl Service

Source

async fn acquire_origins<I>( &self, batch: I, ) -> BTreeMap<OwnedServerName, Vec<OwnedServerSigningKeyId>>
where I: Iterator<Item = (OwnedServerName, Vec<OwnedServerSigningKeyId>)> + Send,

Source§

impl Service

Source

async fn acquire_origin( &self, origin: OwnedServerName, key_ids: Vec<OwnedServerSigningKeyId>, timeout: Instant, ) -> (OwnedServerName, Vec<OwnedServerSigningKeyId>)

Source§

impl Service

Source

async fn acquire_notary<I>( &self, batch: I, ) -> BTreeMap<OwnedServerName, Vec<OwnedServerSigningKeyId>>
where I: Iterator<Item = (OwnedServerName, Vec<OwnedServerSigningKeyId>)> + Send,

Source§

impl Service

Source

async fn acquire_notary_result( &self, missing: &mut BTreeMap<OwnedServerName, Vec<OwnedServerSigningKeyId>>, server_keys: ServerSigningKeys, )

Source§

impl Service

Source

pub async fn get_event_keys( &self, object: &CanonicalJsonObject, version: &RoomVersionRules, ) -> Result<PubKeyMap>

Resolves the public keys required to verify an event.

Invalid signature metadata returns an error. Fetch failures for individual keys are omitted, so a successful result can still be a partial key map.

Source§

impl Service

Source

pub async fn get_pubkeys<'a, S, K>(&self, batch: S) -> PubKeyMap
where S: Iterator<Item = (&'a ServerName, K)> + Send, K: Iterator<Item = &'a ServerSigningKeyId> + Send,

Resolves public-key sets for a batch of servers and key IDs.

Every requested server is inserted, even when its key set is empty. Individual key errors are suppressed by Self::get_pubkeys_for.

Source§

impl Service

Source

pub async fn get_pubkeys_for<'a, I>( &self, origin: &ServerName, key_ids: I, ) -> PubKeys
where I: Iterator<Item = &'a ServerSigningKeyId> + Send,

Resolves the requested public keys for one server.

Keys that cannot be loaded or fetched are omitted, making the returned set intentionally partial rather than failing the whole request.

Source§

impl Service

Source

pub async fn get_verify_key( &self, origin: &ServerName, key_id: &ServerSigningKeyId, ) -> Result<VerifyKey>

Retrieves one current or retired verify key for a server.

The cache is checked first. Trusted notaries and the origin are then queried in configured order, with origin requests disabled in notary-only mode.

Source§

impl Service

Source

async fn get_verify_key_from_notaries( &self, origin: &ServerName, key_id: &ServerSigningKeyId, ) -> Result<VerifyKey>

Source§

impl Service

Source

async fn get_verify_key_from_origin( &self, origin: &ServerName, key_id: &ServerSigningKeyId, ) -> Result<VerifyKey>

Source§

impl Service

Source

pub(super) async fn batch_notary_request<'a, S, K>( &self, notary: &ServerName, batch: S, ) -> Result<Vec<ServerSigningKeys>>
where S: Iterator<Item = (&'a ServerName, K)> + Send, K: Iterator<Item = &'a ServerSigningKeyId> + Send,

Requests a batch of signing-key documents from one trusted notary.

The request is split by configured batch size and concurrency. Malformed individual documents are skipped, while a failed batch aborts the operation.

Source§

impl Service

Source

pub async fn notary_request( &self, notary: &ServerName, target: &ServerName, ) -> Result<impl Iterator<Item = ServerSigningKeys> + Clone + Debug + Send + use<>>

Requests signing-key documents for one target from a trusted notary.

The query requires the configured minimum validity horizon. Malformed documents in an otherwise successful response are omitted from the iterator.

Source§

impl Service

Source

pub async fn server_request( &self, target: &ServerName, ) -> Result<ServerSigningKeys>

Requests the current signing-key document directly from its origin server.

The response must deserialize and name the requested target; a mismatched server_name is rejected as a bad server response.

Source§

impl Service

Source

pub fn gen_id_hash_and_sign_event( &self, object: &mut CanonicalJsonObject, room_version_id: &RoomVersionId, ) -> Result<OwnedEventId>

Generates an event ID, content hash, and local signature in place.

Any existing event_id is removed first. Legacy room versions generate and insert the ID before signing; newer versions derive it after signing and then insert it into the returned object.

Source§

impl Service

Source

fn gen_id_hash_and_sign_event_v1( &self, object: &mut CanonicalJsonObject, room_version_id: &RoomVersionId, ) -> Result<OwnedEventId>

Generates and inserts an event ID before signing a legacy-format event.

The explicit ID participates in the content hash and signature for room versions whose event format requires it.

Source§

impl Service

Source

fn gen_id_hash_and_sign_event_v3( &self, object: &mut CanonicalJsonObject, room_version_id: &RoomVersionId, ) -> Result<OwnedEventId>

Signs a modern-format event before deriving and inserting its event ID.

The derived ID therefore reflects the signed event representation used by room versions that omit an explicit ID during signing.

Source§

impl Service

Source

pub fn hash_and_sign_event( &self, object: &mut CanonicalJsonObject, room_version_id: &RoomVersionId, ) -> Result

Adds a content hash and local server signature to an event object.

Signing uses the room version’s redaction rules. Oversized PDUs are mapped to a request-too-large error and other signing failures to an unknown request error.

Source§

impl Service

Source

pub fn sign_json(&self, object: &mut CanonicalJsonObject) -> Result

Signs an arbitrary canonical JSON object with the local server key.

The signature is inserted under the configured local server name without adding an event content hash.

Source§

impl Service

Source

pub async fn validate_and_add_event_id( &self, pdu: &RawJsonValue, room_version_id: &RoomVersionId, ) -> Result<(OwnedEventId, CanonicalJsonObject)>

Derives an event ID, runs event verification, and returns canonical JSON.

Missing verification keys may be fetched. Newer room versions receive the derived event_id after any successful [Verified] result, including the signatures-only classification produced for a content-hash mismatch.

Source§

impl Service

Source

pub async fn validate_and_add_event_id_no_fetch( &self, pdu: &RawJsonValue, room_version_id: &RoomVersionId, ) -> Result<(OwnedEventId, CanonicalJsonObject)>

Derives and checks an event using only keys already in local storage.

The method rejects the event before verification when any required key is absent. Any successful [Verified] classification is accepted, including a signatures-only result after a content-hash mismatch.

Source§

impl Service

Source

pub async fn verify_event( &self, event: &CanonicalJsonObject, room_version_id: Option<&RoomVersionId>, ) -> Result<Verified>

Verifies an event and returns ruma’s verification classification.

Required keys are loaded or fetched through Self::get_event_keys. When no room version is supplied, version 11 rules are used. Callers must inspect [Verified] to distinguish complete verification from signatures only.

Source§

impl Service

Source

pub async fn verify_json( &self, event: &CanonicalJsonObject, room_version_id: Option<&RoomVersionId>, ) -> Result

Verifies signatures on a canonical JSON object.

Unlike Self::verify_event, this does not verify an event content hash. Version 11 signature rules are used when no room version is supplied.

Source§

impl Service

Source

pub fn keypair(&self) -> &Ed25519KeyPair

Returns the local Ed25519 signing keypair.

The keypair is loaded or generated when the service is built and remains fixed for the service lifetime.

Source§

impl Service

Source

pub fn active_key_id(&self) -> &ServerSigningKeyId

Returns the signing-key ID for the active local verify key.

This delegates to Self::active_verify_key and therefore panics if the service was initialized without an active key.

Source§

impl Service

Source

pub fn active_verify_key(&self) -> (&ServerSigningKeyId, &VerifyKey)

Returns the active local signing-key ID and verify key.

Initialization normally supplies exactly one entry. A missing entry panics, and debug builds also assert that no second active key exists.

Source§

impl Service

Source

async fn add_signing_keys(&self, new_keys: ServerSigningKeys)

Merges a fetched signing-key document into the local cache.

Only current and old verify-key maps are retained from the incoming document; its signatures and validity timestamp are not preserved. The read, merge, and write sequence is not atomic.

Source§

impl Service

Source

pub async fn required_keys_exist( &self, object: &CanonicalJsonObject, rules: &RoomVersionRules, ) -> bool

Checks whether every signature key required by an event is cached.

Invalid signature metadata, database errors, and malformed stored key data all produce false; this method never fetches missing keys.

Source§

impl Service

Source

pub async fn verify_key_exists( &self, origin: &ServerName, key_id: &ServerSigningKeyId, ) -> bool

Checks whether one current or retired verify key is cached for a server.

The check is based on key-ID presence only and does not evaluate the stored key document’s validity interval. Read or decoding errors produce false.

Source§

impl Service

Source

pub async fn verify_keys_for(&self, origin: &ServerName) -> VerifyKeys

Returns all cached verify keys usable for a server.

Retired keys are converted and merged with current keys. Storage errors are suppressed to an empty map, and the local active key is added for our names.

Source§

impl Service

Source

pub async fn signing_keys_for( &self, origin: &ServerName, ) -> Result<ServerSigningKeys>

Loads the cached signing-key document for a server.

The returned document reflects the service’s merged cache representation; reads do not enforce valid_until_ts. Acquisition currently preserves key maps but not incoming document signatures or validity metadata.

Source§

impl Service

Source

fn minimum_valid_ts(&self) -> MilliSecondsSinceUnixEpoch

Trait Implementations§

Source§

impl Service for Service

Source§

fn build(args: &Args<'_>) -> Result<Arc<Self>>

Implement the construction of the service instance. Services are generally singletons so expect this to only be called once for a service type. Note that it may be called again after a server reload, but the prior instance will have been dropped first. Failure will shutdown the server with an error.
Source§

fn name(&self) -> &str

Return the name of the service. i.e. crate::service::make_name(std::module_path!())
Source§

fn worker<'async_trait>( self: Arc<Self>, ) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>
where Self: 'async_trait,

Implement the service’s worker loop. The service manager spawns a task and calls this function after all services have been built.
Source§

fn interrupt<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Interrupt the service. This is sent to initiate a graceful shutdown. The service worker should return from its work loop.
Source§

fn clear_cache<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clear any caches or similar runtime state.
Source§

fn memory_usage<'life0, 'life1, 'async_trait>( &'life0 self, _out: &'life1 mut (dyn Write + Send), ) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Memory usage report in a markdown string.
Source§

fn unconstrained(&self) -> bool

Return true if the service worker opts out of the tokio cooperative budgeting. This can reduce tail latency at the risk of event loop starvation.

Auto Trait Implementations§

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
§

impl<T> DropFlavorWrapper<T> for T

§

type Flavor = MayDrop

The DropFlavor that [wrap]s T into Self
Source§

impl<T> ExpectInto for T

Source§

fn expect_into<Dst>(self) -> Dst
where Dst: TryFrom<Self>, 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: Sized + CheckedAdd,

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

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

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

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

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

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

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

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

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, 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> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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> Tried for T

Source§

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

Adds rhs with checked arithmetic. Read more
Source§

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

Subtracts rhs with checked arithmetic. Read more
Source§

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

Multiplies by rhs with checked arithmetic. Read more
Source§

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

Divides by rhs with checked arithmetic. Read more
Source§

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

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

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

fn try_from(value: U) -> Result<T, !>

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