Skip to main content

Service

Struct Service 

Source
pub struct Service {
    pub mutex_federation: MutexMap<OwnedRoomId, ()>,
    services: Arc<OnceServices>,
    db: Data,
}

Fields§

§mutex_federation: MutexMap<OwnedRoomId, ()>

Serializes room federation as the outermost per-room operation.

Acquire it before the state or timeline insertion mutex for the same room. The canonical order is federation, state, then insertion.

§services: Arc<OnceServices>§db: Data

Implementations§

Source§

impl Service

Source

pub async fn acl_check( &self, server_name: &ServerName, room_id: &RoomId, ) -> Result

Returns Ok if the acl allows the server

Source§

impl Service

Source

pub(super) fn record_attempt(&self, ctx: Context, event_id: &EventId)

Record a federation attempt before a cancellable await, so a premature cancellation still leaves a Pending row behind to rate-gate against.

Source§

impl Service

Source

pub(super) fn record_outcome( &self, ctx: Context, event_id: &EventId, disposition: Disposition, )

Source§

impl Service

Source

pub async fn clear_upgrade_backoff(&self, event_id: &EventId)

Clears the upgrade backoff recorded against an event.

The soft-fail marker and this backoff gate the same retry, so operator recovery has to drop both for the next delivery to evaluate the event without waiting out the window.

Source§

impl Service

Source

pub(super) async fn record_success(&self, ctx: Context, event_id: &EventId)

Source§

impl Service

Source

pub(super) async fn is_suppressed( &self, ctx: Context, event_id: &EventId, range: Range<Duration>, ) -> Suppression

Source§

impl Service

Source

pub(super) async fn fetch_auth<'a, Events>( &self, origin: &ServerName, room_id: &RoomId, events: Events, room_version: &RoomVersionId, recursion_level: usize, ) -> Vec<(PduEvent, Option<CanonicalJsonObject>)>
where Events: Iterator<Item = &'a EventId> + Clone + Send,

Find the event and auth it. Once the event is validated (steps 1 - 8) it is appended to the outliers Tree.

Returns pdu and if we fetched it over federation the raw json.

a. Look in the main timeline (pduid_pdu tree) b. Look at outlier pdu tree c. Ask origin server over federation d. TODO: Ask other servers over federation?

Source§

impl Service

Source

async fn fetch_auth_chain( &self, origin: &ServerName, room_id: &RoomId, event_id: &EventId, room_version: &RoomVersionId, ) -> (OwnedEventId, Option<PduEvent>, Vec<(OwnedEventId, CanonicalJsonObject)>)

Source§

impl Service

Source

pub(super) async fn fetch_prev<'a, Events>( &self, origin: &ServerName, room_id: &RoomId, incoming_event_id: &EventId, initial_set: Events, room_version: &RoomVersionId, recursion_level: usize, first_ts_in_room: MilliSecondsSinceUnixEpoch, ) -> Result<(Vec<OwnedEventId>, HashMap<OwnedEventId, (PduEvent, CanonicalJsonObject)>)>
where Events: Iterator<Item = &'a EventId> + Clone + Send,

Source§

impl Service

Source

async fn await_prev_gap<'a, Events>( &self, initial_set: Events, wait: Duration, ) -> bool
where Events: Iterator<Item = &'a EventId> + Send,

Source§

impl Service

Source

async fn prefetch_missing_events( &self, origin: &ServerName, room_id: &RoomId, incoming_event_id: &EventId, room_version: &RoomVersionId, recursion_level: usize, )

Fill the prev gap below incoming_event_id with one /get_missing_events batch, landing each returned event as a local outlier so the per-event walk resolves it without a federation fetch. latest_events is the held event the server walks back from, bounded by our forward extremities so it returns only the gap; best effort, so a failed batch or rejected event just leaves that id for the walk.

Source§

impl Service

Source

async fn land_missing_event( &self, origin: &ServerName, room_id: &RoomId, pdu: &RawJsonValue, room_version: &RoomVersionId, recursion_level: usize, ) -> Result

Authenticate and persist one event from the missing-events batch as an outlier, deriving its id from content rather than trusting a requested id.

Source§

impl Service

Source

pub(super) async fn fetch_state( &self, origin: &ServerName, room_id: &RoomId, event_id: &EventId, room_version: &RoomVersionId, recursion_level: usize, create_event_id: &EventId, ) -> Result<Option<HashMap<u64, OwnedEventId>>>

Call /state_ids to find out what the state at this pdu is. We trust the server’s response to some extend (sic), but we still do a lot of checks on the events

Source§

impl Service

Source

pub fn handle_incoming_pdu<'a>( &'a self, __arg1: &'a ServerName, __arg2: &'a RoomId, __arg3: &'a EventId, __arg4: CanonicalJsonObject, __arg5: bool, ) -> Pin<Box<dyn Future<Output = Result<Option<(RawPduId, bool)>>> + Send + 'a>>

When receiving an event one needs to: 0. Check the server is in the room

  1. Skip the PDU if we already know about it 1.1. Remove unsigned field
  2. Check signatures, otherwise drop
  3. Check content hash, redact if doesn’t match
  4. Fetch any missing auth events doing all checks listed here starting at 1. These are not timeline events
  5. Reject “due to auth events” if can’t get all the auth events or some of the auth events are also rejected “due to auth events”
  6. Reject “due to auth events” if the event doesn’t pass auth based on the auth events
  7. Persist this event as an outlier
  8. If not timeline event: stop
  9. Fetch any missing prev events doing all checks listed here starting at 1. These are timeline events
  10. Fetch missing state and auth chain events by calling /state_ids at backwards extremities doing all the checks in this list starting at
    1. These are not timeline events
  11. Check the auth of the event passes based on the state of the event
  12. Ensure that the state is derived from the previous current state (i.e. we calculated by doing state res where one of the inputs was a previously trusted set of state, don’t just trust a set of state we got from a remote)
  13. Use state resolution to find new room state
  14. Check if the event passes auth based on the “current state” of the room, if not soft fail it
Source

async fn __handle_incoming_pdu<'a>( &'a self, origin: &'a ServerName, room_id: &'a RoomId, event_id: &'a EventId, pdu: CanonicalJsonObject, is_timeline_event: bool, ) -> Result<Option<(RawPduId, bool)>>

Source§

impl Service

Source

async fn handle_rescinded_invite( &self, room_id: &RoomId, pdu: &CanonicalJsonObject, ) -> Result<bool>

Apply a federated leave that rescinds an out-of-band invite for a local user.

We are not resident in the room, so the kick cannot be processed as a normal timeline event for lack of room state; but it must still clear the invite so the invited user’s /sync reflects the rescission. Mirrors Synapse’s out-of-band membership handling: only a kick from the original inviter is honored, since without the room state we cannot judge any other sender’s authority. Returns true when a rescission was applied.

Source§

impl Service

Source

async fn handle_prev_events( &self, origin: &ServerName, room_id: &RoomId, event_id: &EventId, sorted_prev_events: Vec<OwnedEventId>, eventid_info: HashMap<OwnedEventId, (PduEvent, CanonicalJsonObject)>, room_version: &RoomVersionId, recursion_level: usize, first_ts_in_room: MilliSecondsSinceUnixEpoch, create_event_id: &EventId, ) -> Result<()>

Upgrade an incoming PDU’s previous events, walking interior events after their parents so each derives state locally instead of refetching it.

Source§

impl Service

Source

async fn upgrade_prev_event( &self, origin: &ServerName, room_id: &RoomId, event_id: &EventId, info: Option<(PduEvent, CanonicalJsonObject)>, room_version: &RoomVersionId, recursion_level: usize, first_ts_in_room: MilliSecondsSinceUnixEpoch, prev_id: OwnedEventId, create_event_id: &EventId, ) -> Result<(OwnedEventId, Option<(RawPduId, bool)>)>

Upgrade one previous event, folding a transient failure into a no-op so a single bad prev does not abort the batch; a shutdown still propagates.

Source§

impl Service

Source

pub(super) async fn handle_outlier_pdu( &self, origin: &ServerName, room_id: &RoomId, event_id: &EventId, pdu_json: CanonicalJsonObject, room_version: &RoomVersionId, recursion_level: usize, auth_events_known: bool, ) -> Result<(PduEvent, CanonicalJsonObject)>

Source§

impl Service

Source

pub(super) async fn handle_prev_pdu( &self, origin: &ServerName, room_id: &RoomId, event_id: &EventId, eventid_info: Option<(PduEvent, CanonicalJsonObject)>, room_version: &RoomVersionId, recursion_level: usize, first_ts_in_room: MilliSecondsSinceUnixEpoch, prev_id: &EventId, create_event_id: &EventId, ) -> Result<Option<(RawPduId, bool)>>

Source§

impl Service

Source

pub(super) async fn cached_resolved_state( &self, event_id: &EventId, ) -> Option<HashMap<u64, OwnedEventId>>

State resolved for an event not in our timeline, keyed by event id, held only to spare a repeat /state_ids fetch on the next walk. The value is a shortstatehash into the shared compressor tables, never the authoritative shorteventid_shortstatehash, so no authoritative state read observes it.

Source§

impl Service

Source

pub(super) async fn cache_resolved_state( &self, room_id: &RoomId, event_id: &EventId, state: Arc<CompressedState>, )

Persist the state resolved for event_id over federation so a later walk of the same event resolves without another fetch. Best effort: a failed compressor write leaves the next walk to refetch.

Source§

impl Service

Source

pub async fn parse_incoming_pdu( &self, pdu: &RawJsonValue, ) -> Result<(OwnedRoomId, OwnedEventId, CanonicalJsonObject)>

Source§

impl Service

Source

async fn invited_room_version(&self, room_id: &RoomId) -> Option<RoomVersionId>

Recover a room’s version from a locally-invited member’s stored stripped state, for a room we are not resident in (e.g. a rescinded out-of-band invite). The create event in the stripped state carries the version.

Source§

impl Service

Source

pub fn clear_policy_signature_state(&self, event_id: &EventId)

Clears the cached policy server decision for an event.

A later validation can contact the policy server again.

Source§

impl Service

Source

fn cache_policy_refused(&self, event_id: &EventId)

Source§

impl Service

Source

fn cache_policy_backoff(&self, event_id: &EventId, until_secs: u64)

Source§

impl Service

Source

async fn cached_policy_state( &self, event_id: &EventId, ) -> Option<PolicySigState>

Source§

impl Service

Source

pub async fn lookup_policy_server( &self, room_id: &RoomId, ) -> Option<RoomPolicyEventContent>

Returns the room’s policy event content when a policy server is in effect: state event present (stable m.room.policy, falling back to MSC4284’s unstable org.matrix.msc4284.policy), parses cleanly under either the stable public_keys map or the unstable singular public_key field, and the via server has a joined user in the room. Any failure returns None, signalling “no policy server configured” so the caller skips the gate entirely.

Source§

impl Service

Source

pub async fn sign_outgoing_pdu<E>( &self, pdu_json: &mut CanonicalJsonObject, pdu: &E, ) -> Result
where E: Event,

MSC4284: ask the room’s policy server to sign an outgoing event. The signature is folded into pdu_json["signatures"] so it persists with the event and federates transitively to other servers in the room. Returns Forbidden when the policy server explicitly refuses; network errors and timeouts fail open with a warn log.

Source§

impl Service

Source

async fn fetch_policy_signature( &self, policy: &RoomPolicyEventContent, pdu_json: &CanonicalJsonObject, room_version: &RoomVersionId, ) -> FetchOutcome

Calls the policy server’s /sign endpoint. The classification of the response (Signed / Refused / RateLimited / FailOpen) lets each caller choose its own reaction.

Source§

impl Service

Source

pub async fn verify_or_fetch_inbound_policy_signature<E>( &self, pdu_json: &mut CanonicalJsonObject, pdu: &E, ) -> PolicyCheck
where E: Event,

MSC4284: verify the inbound PDU’s policy server signature.

Missing or invalid signatures are fetched again because the policy server’s key may have rotated. A fetched signature is folded into the event.

Source§

impl Service

Source

async fn fetch_inbound_policy_signature<E>( &self, pdu_json: &mut CanonicalJsonObject, pdu: &E, ) -> PolicyCheck
where E: Event,

MSC4284: fetch a missing or invalid inbound policy server signature.

The signature is folded into pdu_json so it persists and federates onward. Refusals map to Invalid; transient failures map to Pass.

Source§

impl Service

Source

pub async fn check_inbound_policy_signature<E>( &self, pdu_json: &CanonicalJsonObject, pdu: &E, ) -> PolicyCheck
where E: Event,

MSC4284: verify the policy server signature on an inbound PDU. Returns NotApplicable for rooms without a configured policy server (the gate is skipped); Pass when the signature verifies; Missing when no signature is present for the configured server; Invalid when the signature is present but cryptographic verification fails.

Source§

impl Service

Source

pub async fn resolve_state( &self, room_id: &RoomId, room_version: &RoomVersionId, incoming_state: HashMap<u64, OwnedEventId>, ) -> Result<Arc<CompressedState>>

Source§

impl Service

Source

pub(super) async fn state_resolution<StateSets, AuthSets>( &self, _room_id: &RoomId, room_version: &RoomVersionId, state_sets: StateSets, auth_chains: AuthSets, ) -> Result<StateMap<OwnedEventId>>
where StateSets: Stream<Item = StateMap<OwnedEventId>> + Send, AuthSets: Stream<Item = AuthSet<OwnedEventId>> + Send,

Source§

impl Service

Source

pub(super) async fn state_at_incoming_degree_one<Pdu>( &self, incoming_pdu: &Pdu, ) -> Result<Option<HashMap<u64, OwnedEventId>>>
where Pdu: Event,

Source§

impl Service

Source

pub(super) async fn state_at_incoming_resolved<Pdu>( &self, incoming_pdu: &Pdu, room_id: &RoomId, room_version: &RoomVersionId, ) -> Result<Option<HashMap<u64, OwnedEventId>>>
where Pdu: Event,

Source§

impl Service

Source

async fn state_at_incoming_fork<Pdu>( &self, room_id: &RoomId, room_version: &RoomVersionId, sstatehash: ShortStateHash, prev_event: Pdu, ) -> Result<(StateMap<OwnedEventId>, AuthSet<OwnedEventId>)>
where Pdu: Event,

Source§

impl Service

Source

pub(super) async fn fork_state<'a, State>( &'a self, state: State, ) -> StateMap<OwnedEventId>
where State: Iterator<Item = (ShortStateKey, &'a OwnedEventId)> + Send + 'a,

Converts one fork branch from short state keys to typed state keys.

A later duplicate state key replaces an earlier entry. Short state key lookup failures are omitted.

Source§

impl Service

Source

pub(super) async fn fork_chain<'a, Events>( &'a self, room_id: &'a RoomId, room_version: &'a RoomVersionId, starting_events: Events, ) -> Result<AuthSet<OwnedEventId>>
where Events: Iterator<Item = &'a EventId> + Clone + ExactSizeIterator + Send + 'a,

Collects the full auth chain for one fork branch.

The ids are distinct as AuthSet::from_distinct requires: the chain walk dedups short ids and the short-to-event-id mapping is injective. Iteration order is arbitrary.

Source§

impl Service

Source

pub(super) async fn state_at_incoming_local<Pdu>( &self, room_id: &RoomId, incoming_pdu: &Pdu, room_version: &RoomVersionId, create_event_id: &EventId, mode: WalkMode, ) -> Result<Option<HashMap<ShortStateKey, OwnedEventId>>>
where Pdu: Event,

Build the state before incoming_pdu from events we already hold, walking locally held uncommitted ancestry down to committed or memoized ancestors with an auth gate on every folded state event. Some(map) is a complete gated build in the shape the sibling builders return; None falls back to the federation state fetch, for any reason. Err propagates only server shutdown and room-version failures.

Source§

impl Service

Source

async fn walk_task( &self, room_id: OwnedRoomId, room_version: RoomVersionId, create_event_id: OwnedEventId, mode: WalkMode, top_prevs: PrevEvents, parent: Span, ) -> Result<Option<HashMap<ShortStateKey, OwnedEventId>>>

Walk body on its own task: a poll descends every combinator layer from the task root, and under /send intake, already the server’s deepest stack, the walk’s auth-gate subtree overflows the worker stack in debug builds.

Source§

impl Service

Source

pub async fn local_state_report( &self, event_id: &EventId, ) -> Result<LocalBuildReport>

Run a read-only (shadow-mode) walk for one stored event and describe the outcome, for the admin debug command.

Source§

impl Service

Source

async fn walk_state( &self, walk: &mut Walk<'_>, ) -> Result<Option<HashMap<ShortStateKey, OwnedEventId>>>

Drive discovery then the post-order build; any abnormality sets walk.fallback and yields None.

Source§

impl Service

Source

async fn walk_discover(&self, walk: &mut Walk<'_>) -> Result

Classify the uncommitted ancestry below the incoming event with point reads only, emitting held nodes in post-order; every condition the build cannot survive sets walk.fallback here, before any state materializes.

Source§

impl Service

Source

async fn walk_auth_present(&self, walk: &Walk<'_>, pdu: &PduEvent) -> bool

The auth gate must stay evaluable: every auth event of a held node has to be present locally before the walk commits to building through it. Hydra rooms chain the create event implied by the room id.

Source§

impl Service

Source

async fn walk_build( &self, walk: &mut Walk<'_>, ) -> Result<Option<HashMap<ShortStateKey, OwnedEventId>>>

Compute state through the walk sub-DAG in post-order, so every node’s prevs resolve before it, then combine at the incoming event’s own prevs.

Source§

impl Service

Source

async fn walk_node(&self, walk: &mut Walk<'_>, index: usize) -> bool

Resolve one held node: state-before from its prevs, its own gated fold on top, retained until the last consumer releases it.

Source§

impl Service

Source

async fn state_after( &self, walk: &mut Walk<'_>, event_id: &EventId, ) -> Option<Arc<HashMap<ShortStateKey, OwnedEventId>>>

State after one prev: an already-resolved node or materialized frontier entry shares its map; otherwise the frontier materializes here.

Source§

impl Service

Source

async fn committed_state_after( &self, walk: &mut Walk<'_>, event_id: &EventId, shortstatehash: ShortStateHash, ) -> Option<Arc<HashMap<ShortStateKey, OwnedEventId>>>

State after a committed frontier event: its stored state plus its own key folded unguarded, exactly the degree-one builder’s shape; a committed event passed full state-dependent auth at its own upgrade.

Source§

impl Service

Source

async fn memoized_state_after( &self, walk: &mut Walk<'_>, event_id: &EventId, ) -> Option<Arc<HashMap<ShortStateKey, OwnedEventId>>>

State after a memoized frontier event: the memo row is its state-before (the column’s uniform meaning), so its own gated fold recomputes on top.

Source§

impl Service

Source

async fn gated_fold( &self, room_rules: &RoomVersionRules, gate_drops: &mut usize, pdu: &PduEvent, before: &Arc<HashMap<ShortStateKey, OwnedEventId>>, ) -> Arc<HashMap<ShortStateKey, OwnedEventId>>

Fold the event’s own state key over its state-before, only when the position-correct auth gate passes; a rejection leaves state unchanged. Discovery pre-verified the auth events exist locally, so a gate error is a deterministic auth verdict, not an unevaluable input.

Source§

impl Service

Source

async fn fork_resolve( &self, walk: &mut Walk<'_>, prevs: &[OwnedEventId], memo_event_id: Option<&EventId>, ) -> Option<Arc<HashMap<ShortStateKey, OwnedEventId>>>

State before a fork node, resolving the state after each of its prevs exactly as the committed-prev fork resolves today. Fork outputs are the artifacts worth memoizing; chain nodes are cheap to re-derive.

Source§

impl Service

Source

pub(super) async fn upgrade_outlier_to_timeline_pdu( &self, origin: &ServerName, room_id: &RoomId, incoming_pdu: PduEvent, pdu_json: CanonicalJsonObject, room_version: &RoomVersionId, recursion_level: usize, create_event_id: &EventId, ) -> Result<Option<(RawPduId, bool)>>

Source§

impl Service

Source

async fn current_state_auth_passes( &self, room_id: &RoomId, incoming_pdu: &PduEvent, room_rules: &RoomVersionRules, ) -> bool

Source§

impl Service

Source

async fn soft_fail_standing( &self, incoming_pdu: &PduEvent, room_rules: &RoomVersionRules, pdu_json: &mut CanonicalJsonObject, ) -> Result<Standing>

Re-examines an event that already carries a soft-fail marker.

The marker is a standing verdict rather than a permanent rejection, so it lapses on the upgrade backoff and the event is weighed again. Asking before state resolution keeps a still-refused event cheap to decline, since a cached policy answer needs no round trip.

Source§

impl Service

Source

async fn resolve_state_at_incoming_event( &self, origin: &ServerName, room_id: &RoomId, incoming_pdu: &PduEvent, room_version: &RoomVersionId, recursion_level: usize, create_event_id: &EventId, ) -> Result<(HashMap<u64, OwnedEventId>, ResolvedVia)>

Source§

impl Service

Source

async fn auth_check_outlier_pdu( &self, room_id: &RoomId, incoming_pdu: &PduEvent, room_rules: &RoomVersionRules, state_at_incoming_event: &HashMap<u64, OwnedEventId>, ) -> Result

Source§

impl Service

Source

async fn compute_soft_fail( &self, incoming_pdu: &PduEvent, room_rules: &RoomVersionRules, pdu_json: &mut CanonicalJsonObject, ) -> Result<bool>

Source§

impl Service

Source

async fn compute_remaining_extremities( &self, room_id: &RoomId, incoming_pdu: &PduEvent, ) -> Vec<OwnedEventId>

Source§

impl Service

Source

async fn resolve_and_force_state_after( &self, room_id: &RoomId, room_version: &RoomVersionId, incoming_pdu: &PduEvent, state_at_incoming_event: &HashMap<u64, OwnedEventId>, state_lock: &RoomMutexGuard, ) -> Result

Source§

impl Service

Source

async fn event_exists(&self, event_id: &EventId) -> bool

Source§

impl Service

Source

async fn event_fetch(&self, event_id: &EventId) -> Result<PduEvent>

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