Skip to main content

Service

Struct Service 

Source
pub struct Service {
    pub db: Data,
    server: Arc<Server>,
    services: Arc<OnceServices>,
    channels: Vec<(Sender<Msg>, Receiver<Msg>)>,
    flushes: Mutex<JoinSet<()>>,
    stalled: Mutex<HashMap<OwnedServerName, Option<Instant>>>,
}
Expand description

Outbound delivery of PDUs and EDUs to federation peers, appservices, and push gateways.

Requests are written as durable queue rows and dispatched to a pool of sender workers sharded by destination.

Fields§

§db: Data§server: Arc<Server>§services: Arc<OnceServices>§channels: Vec<(Sender<Msg>, Receiver<Msg>)>§flushes: Mutex<JoinSet<()>>§stalled: Mutex<HashMap<OwnedServerName, Option<Instant>>>

Implementations§

Source§

impl Service

Source

pub async fn send_to_device_appservices<'a, I>( &self, sender: &'a UserId, target_user: &'a UserId, deliveries: I, event_type: &'a str, content: &'a Value, ) -> Result
where I: Iterator<Item = (&'a DeviceId, u64)> + Send + 'a,

Queue stored to-device events for delivery to interested appservices (MSC4203).

deliveries are the concrete recipient devices already written to the inbox, after AllDevices expansion. Each delivery becomes one queue row per interested appservice, written under one cork; with no interested appservice nothing is serialized.

Source§

impl Service

Source

pub async fn send_device_list_appservices( &self, user_id: &UserId, count: u64, ) -> Result

Queue a device_lists.changed marker (MSC3202) for delivery to appservices that opted into transaction extensions and are interested in user_id.

The caller passes the count it already allocated so the marker uniquifies the transaction hash.

Source§

impl Service

Source

async fn shares_device_list_room( &self, user_id: &UserId, info: &RegistrationInfo, ) -> bool

Whether user_id shares a device-list-interesting room with info.

A joined room the appservice participates in counts when it is encrypted, or unconditionally when device_key_update_encrypted_rooms_only is off.

Source§

impl Service

Source

pub(super) async fn send_events_dest_appservice( &self, id: String, events: Vec<SendingEvent>, ) -> Result<Destination, (Destination, Error)>

Source§

impl Service

Source

async fn txn_part( &self, info: &RegistrationInfo, msc3202: bool, event: &SendingEvent, ) -> Part

Source§

impl Service

Source

async fn msc3202_key_counts( &self, users: BTreeSet<OwnedUserId>, recipients: SmallVec<[(OwnedUserId, OwnedDeviceId); 1]>, ) -> (BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, BTreeMap<OneTimeKeyAlgorithm, UInt>>>, BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, Vec<OneTimeKeyAlgorithm>>>)

MSC3202 one-time-key counts and unused fallback key types over every device of users plus the specific recipients.

Recomputed per build rather than snapshotted, so a retry ships fresh counts.

Source§

impl Service

Source

pub(super) async fn send_events_dest_federation( &self, server: OwnedServerName, events: Vec<SendingEvent>, ) -> (Result<Destination, (Destination, Error)>, bool)

Send a federation transaction, reporting whether one went out at all.

Rows that all fail to load leave nothing to send; they still succeed, so their keys are acknowledged.

Source§

impl Service

Source

pub fn schedule_flush_suppressed_for_pushkey( &self, user_id: OwnedUserId, pushkey: String, reason: &'static str, )

Schedule a flush of the pushes suppressed for one pushkey.

The flush runs as a task this service owns, so the caller never waits on the push gateway.

Source§

impl Service

Source

pub fn schedule_flush_suppressed_for_user( &self, user_id: OwnedUserId, reason: &'static str, )

Schedule a flush of the pushes suppressed for every pushkey a user owns.

The flush runs as a task this service owns, so the caller never waits on the push gateway.

Source§

impl Service

Source

async fn flush_suppressed_for_pushkey( &self, user_id: &UserId, pushkey: &str, reason: &'static str, )

Source§

impl Service

Source

async fn flush_suppressed_for_user( &self, user_id: &UserId, reason: &'static str, )

Source§

impl Service

Source

async fn flush_suppressed_rooms( &self, flush: &Flush<'_>, rooms: SuppressedRooms, )

Source§

impl Service

Source

async fn flush_suppressed_room( &self, flush: &Flush<'_>, room_id: OwnedRoomId, pdu_ids: Vec<RawPduId>, ) -> usize

Source§

impl Service

Source

async fn flush_suppressed_pdu( &self, flush: &Flush<'_>, room_id: &RoomId, pdu_id: RawPduId, pdu: &Pdu, ) -> bool

Source§

impl Service

Source

pub(super) async fn enqueue_suppressed_push_events( &self, user_id: &UserId, pushkey: &str, events: &[SendingEvent], ) -> usize

Source§

impl Service

Source

async fn suppressable_pdu( &self, user_id: &UserId, pdu_id: &RawPduId, ) -> Option<Pdu>

Load a suppressed PDU if a push for it is still worth sending.

A missing or redacted PDU is dropped with a log line and never notified.

Source§

impl Service

Source

pub(super) async fn pushing_suppressed(&self, user_id: &UserId) -> bool

Decide whether pushes for a user are suppressed as active.

The heuristic combines the presence age and the most recent sync gap, and only applies when suppress_push_when_active is enabled. An offline user is never suppressed; the two ACTIVE_* constants are the thresholds.

Source§

impl Service

Source

pub(super) async fn send_events_dest_push( &self, user_id: OwnedUserId, pushkey: String, events: Vec<SendingEvent>, ) -> Result<Destination, (Destination, Error)>

Source§

impl Service

Source

pub(super) fn send_events( &self, dest: Destination, items: Vec<(Vec<u8>, SendingEvent)>, split: Option<Split>, ) -> BoxFuture<'_, Completion>

Source§

impl Service

Source

pub(super) async fn startup_netburst<'a>( &'a self, id: usize, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, statuses: &mut HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source§

impl Service

Source

async fn arm_inherited_destinations( &self, id: usize, statuses: &HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

pub(super) async fn arm_startup_wake( &self, dest: Destination, index: u64, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, ) -> u64

Source§

impl Service

Source

pub(super) async fn handle_response<'a>( &'a self, __arg1: Completion, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, statuses: &mut HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

async fn handle_response_ok<'a>( &'a self, dest: Destination, split: Option<Split>, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, statuses: &mut HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

async fn handle_response_err<'a>( &'a self, __arg1: (Destination, Error), split: Option<Split>, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, statuses: &mut HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

pub(super) async fn handle_force_retry<'a>( &'a self, dest: Destination, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, statuses: &mut HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

pub(super) async fn select_edus_device_changes( &self, server_name: &ServerName, since: (u64, u64), max_edu_count: &AtomicU64, events_len: &AtomicUsize, ) -> Selected

Select device-list deltas and signing-key updates for local users.

Legacy records and windows exceeding the device limit force a snapshot resync.

Source§

impl Service

Source

async fn select_user_devices( &self, selected: Selected, user_id: &UserId, counts: BTreeSet<u64>, server_name: &ServerName, events_len: &AtomicUsize, ) -> Selected

Source§

impl Service

Source

async fn signing_key_edu( &self, user_id: &UserId, server_name: &ServerName, ) -> Option<EduBuf>

Source§

impl Service

Source

async fn device_delta_edu(&self, user_id: &UserId, delta: Delta<'_>) -> EduBuf

Source§

impl Service

Source

pub(super) async fn select_edus_presence( &self, server_name: &ServerName, since: (u64, u64), max_edu_count: &AtomicU64, events_len: &AtomicUsize, ) -> Option<EduBuf>

Select one presence EDU for the users a server may see.

The window’s local presence transitions collapse into one Edu::Presence carrying the latest state per user. A budget trip drops it, and presence self-heals on the next transition.

Source§

impl Service

Source

async fn presence_update( &self, server_name: &ServerName, user_id: &UserId, presence_bytes: &[u8], ) -> Option<(OwnedUserId, PresenceUpdate)>

The presence update to ship for one transition, if the server may see it.

Source§

impl Service

Source

pub(super) async fn select_edus_receipts( &self, server_name: &ServerName, since: (u64, u64), max_edu_count: &AtomicU64, events_len: &AtomicUsize, ) -> Selected

Select read-receipt EDUs across every room shared with the server.

MSC3771 lets a user emit multiple receipts in the same EDU window, one per thread context. The federation EDU shape allows only one ReceiptData per (room, user) slot, so a user with N parallel thread receipts ships across N parallel Edu::Receipt buffers within the same transaction. Each buffer is shape-compliant; receivers process them as independent receipt EDUs and our storage keeps each thread distinct.

Source§

impl Service

Source

async fn select_edus_receipts_room( &self, room_id: &RoomId, since: (u64, u64), max_edu_count: &AtomicU64, num: &AtomicUsize, ) -> SmallVec<[ReceiptMap; 1]> ⓘ

Look for read receipts in this room.

The receipt-limit budget bounds distinct users only; subsequent thread receipts for an already-counted user do not consume additional budget.

Source§

impl Service

Source

pub(super) async fn select_events( &self, dest: &Destination, new_events: SmallVec<[(Vec<u8>, SendingEvent); 1]>, statuses: &mut HashMap<Destination, TransactionStatus>, ) -> Result<Selection>

Source§

impl Service

Source

async fn select_events_current( &self, dest: &Destination, statuses: &mut HashMap<Destination, TransactionStatus>, retry_action: RetryAction, ) -> Current

Source§

impl Service

Source

fn transition( &self, dest: &Destination, status: &mut TransactionStatus, retry_action: RetryAction, ) -> Current

Advance a destination’s status for a new selection.

Distinguishes busy destinations from permitted selection and active replay.

Source§

impl Service

Source§

impl Service

Source

pub(super) async fn federation_batch( &self, dest: &Destination, server: &ServerName, new_events: SmallVec<[(Vec<u8>, SendingEvent); 1]>, ) -> Selection

Compose a federation destination’s next transaction around its parked rooms.

Each expired park is retried alone first, and one whose room has nothing queued ends. Rows of other parked rooms stay queued, and a destination holding nothing else waits for the earliest park to expire.

Source§

impl Service

Source

async fn claim_new( &self, new_events: SmallVec<[(Vec<u8>, SendingEvent); 1]>, skip: &[ShortRoomId], ) -> Vec<(Vec<u8>, SendingEvent)>

Claim a request’s own queue rows, leaving those of skipped rooms queued.

Flush markers carry no row and are dropped; the claimed rows turn active in one batch.

Source§

impl Service

Source

async fn with_edus( &self, dest: &Destination, server_name: &ServerName, items: Vec<(Vec<u8>, SendingEvent)>, skip: &[ShortRoomId], ) -> Vec<(Vec<u8>, SendingEvent)>

Top up a federation transaction with the EDUs accrued since its last window.

An empty transaction first claims the head of the queue. Rows of the skipped rooms neither join the transaction nor hold back fresh EDUs.

Source§

impl Service

Source

pub(super) async fn resume_queued( &self, dest: &Destination, skip: &[ShortRoomId], ) -> Vec<(Vec<u8>, SendingEvent)>

Claim the head of a destination’s queue as its next transaction.

Rows of the skipped rooms are passed over; the claimed rows turn active in one batch.

Source§

impl Service

Source

pub(super) async fn select_edus( &self, server_name: &ServerName, budget_used: usize, ) -> impl Iterator<Item = (Vec<u8>, SendingEvent)>

Source§

impl Service

Source

pub(super) async fn split_failure( &self, server: &ServerName, error: &Error, split: Option<Split>, tries: u32, ) -> (Option<Split>, u32)

Choose how a failed federation transaction continues.

After repeated failures the transaction’s PDU rows return to the queue and its rooms go out one per transaction; a room failing after a delivery is parked. Returns the split to keep and the failure count its retry backs off by, zero when the split advanced.

Source§

impl Service

Source

async fn control( &self, dest: &Destination, server: &ServerName, rooms: &SmallVec<[ShortRoomId; 2]>, ) -> Option<ShortRoomId>

Find the first queued room outside the split and the server’s parks.

A control delivered while the split’s rooms keep failing implicates those rooms rather than the destination.

Source§

impl Service

Source

pub(super) async fn split_delivered( &self, dest: &Destination, split: Split, ) -> Option<(Vec<(Vec<u8>, SendingEvent)>, Split)>

Advance a split past its delivered head room, ending any park it had.

Returns the next room’s transaction, or nothing once the split is done.

Source§

impl Service

Source

pub(super) async fn slice( &self, dest: &Destination, split: Split, ) -> Option<(Vec<(Vec<u8>, SendingEvent)>, Split)>

Promote the head room’s queued rows as the split’s next transaction.

The split ends when it has no rooms left, or its head room has no rows. The rejected transaction’s EDU rows stay active and ride along until delivered.

Source§

impl Service

Source

pub(super) async fn drain_due_wakes<'a>( &'a self, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, statuses: &mut HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

async fn handle_wake<'a>( &'a self, dest: Destination, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, statuses: &mut HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

async fn handle_federation_wake<'a>( &'a self, server: OwnedServerName, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, statuses: &mut HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

pub(super) async fn arm_federation_wake( &self, server: OwnedServerName, tries: u32, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

pub(super) fn arm_push_wake( &self, dest: Destination, error: &Error, statuses: &HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source§

impl Service

Source

pub(super) async fn sender(self: Arc<Self>, id: usize) -> Result

Source§

impl Service

Source

async fn work_loop<'a>( &'a self, id: usize, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, statuses: &mut HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

async fn handle_request<'a>( &'a self, msg: Msg, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, statuses: &mut HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

fn schedule_events<'a>( &'a self, dest: Destination, selection: Selection, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, statuses: &mut HashMap<Destination, TransactionStatus>, wakes: &mut BinaryHeap<Reverse<(Instant, Destination)>>, )

Source§

impl Service

Source

async fn finish_responses<'a>( &'a self, futures: &mut FuturesUnordered<BoxFuture<'a, Completion>>, )

Source§

impl Service

Source

pub(super) async fn run(self: Arc<Self>) -> Result

Run the sender workers to completion.

One worker is spawned per channel and joined; a panic among them is returned so the manager restarts the service. The suppressed-push flush tasks are then aborted and joined so a panic among them is still reported.

Source§

impl Service

Source

pub(super) fn close(&self)

Source§

impl Service

Source

pub(super) fn dispatch(&self, msg: Msg) -> Result

Source§

impl Service

Source

pub(super) fn shard_id(&self, dest: &Destination) -> usize

Source§

impl Service

Source

pub(super) fn federation_shard_id(&self, server: &ServerName) -> usize

Source§

impl Service

Source

pub(super) fn spawn_flush<F>(&self, flush: F)
where F: Future<Output = ()> + Send + 'static,

Source§

impl Service

Source

pub fn send_pdu_push( &self, pdu_id: &RawPduId, user: &UserId, pushkey: String, ) -> Result

Queue a PDU for delivery to one of a user’s pushers.

The row is durable and the shard owning the destination is woken.

Source§

impl Service

Source§

impl Service

Source

pub async fn refresh_push_badge(&self, user_id: &UserId) -> Result

Queue a counts-only push refresh for every pusher owned by a user.

Rows are durable, coalesced, and recomputed at send time.

Source§

impl Service

Source

pub fn send_pdu_appservice( &self, appservice_id: String, pdu_id: RawPduId, ) -> Result

Queue a PDU for delivery to an appservice.

The row is durable and the shard owning the destination is woken.

Source§

impl Service

Source

pub async fn send_pdu_room(&self, room_id: &RoomId, pdu_id: &RawPduId) -> Result

Queue a PDU for delivery to every remote server in a room.

The fan-out is one durable row per server, dispatched under a single cork.

Source§

impl Service

Source

pub async fn send_pdu_servers<'a, S>( &self, servers: S, pdu_id: &RawPduId, ) -> Result
where S: Stream<Item = &'a ServerName> + Send + 'a,

Queue a PDU for delivery to each of the given servers.

The fan-out is one durable row per server, dispatched under a single cork.

Source§

impl Service

Source

async fn queue_and_dispatch_servers<'a, S>( &self, servers: S, event: SendingEvent, ) -> Result
where S: Stream<Item = &'a ServerName> + Send + 'a,

Source§

impl Service

Source

pub fn send_edu_server(&self, server: &ServerName, serialized: EduBuf) -> Result

Queue an EDU for delivery to a server.

The row is durable and the shard owning the destination is woken.

Source§

impl Service

Source

pub async fn send_edu_room( &self, room_id: &RoomId, serialized: EduBuf, ) -> Result

Queue an EDU for delivery to every remote server in a room.

The fan-out is one durable row per server, dispatched under a single cork.

Source§

impl Service

Source

pub async fn send_edu_servers<'a, S>( &self, servers: S, serialized: EduBuf, ) -> Result
where S: Stream<Item = &'a ServerName> + Send + 'a,

Queue an EDU for delivery to each of the given servers.

The fan-out is one durable row per server, dispatched under a single cork.

Source§

impl Service

Source

pub async fn send_edu_room_appservices<'a, F>( &self, room_id: &RoomId, serializer: F, ) -> Result
where F: Fn(&mut dyn Write) -> Result + Send + 'a, &'a F: Send + Sync,

Queue an EDU for every appservice interested in a room.

An appservice is interested when it receives ephemeral events and the room is in its namespace, it is present in the room, or one of the room’s local aliases matches. The serializer writes EphemeralData, not a federation Edu, once per matching appservice.

Source§

impl Service

Source

pub fn send_edu_appservice( &self, appservice_id: String, serialized: EduBuf, ) -> Result

Queue an EDU for delivery to a specific appservice.

The row is durable and the shard owning the destination is woken.

Source§

impl Service

Source

pub async fn flush_room(&self, room_id: &RoomId) -> Result

Wake the sender for every remote server in a room.

A flush is not queued as a row; it only prompts the shard to compose a transaction from whatever is pending.

Source§

impl Service

Source

pub async fn flush_servers<'a, S>(&self, servers: S) -> Result
where S: Stream<Item = &'a ServerName> + Send + 'a,

Wake the sender for each of the given servers.

A flush is not queued as a row; it only prompts the shard to compose a transaction from whatever is pending.

Source§

impl Service

Source§

impl Service

Source

pub fn flush_appservice(&self, appservice_id: String) -> Result

Wake the sender for an appservice.

A flush is not queued as a row; it only prompts the shard to compose a transaction from whatever is pending.

Source§

impl Service

Source

pub async fn notify_peer_alive(&self, server: &ServerName) -> bool

Wake the sender for a federation peer that has proven reachable.

Reachability comes from inbound activity or an operator reset. The flush resumes a waiting sender generation after its notification floor, or immediately when peer failure rows existed. The return value reports only whether those peer rows existed.

Source§

impl Service

Source

pub async fn cleanup_events( &self, appservice_id: Option<&str>, user_id: Option<&UserId>, push_key: Option<&str>, ) -> Result

Clean up queued sending event data.

Accepts either an appservice ID alone, after its registration is removed, or a user ID with a push key, after the pusher is deleted; any other combination is ignored with a warning.

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 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 name(&self) -> &str

Return the name of the service. i.e. crate::service::make_name(std::module_path!())
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.
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.

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