Skip to main content

TransportManager

Struct TransportManager 

Source
pub struct TransportManager { /* private fields */ }
Expand description

Manages multiple transports and handles transport selection.

Implementations§

Source§

impl TransportManager

Source

pub fn new(selector: TransportSelector) -> Self

Creates a new transport manager with default configuration.

Source

pub fn set_device_battery(&mut self, level: u8, is_charging: bool)

Records the host’s battery reading for this device.

Battery is a property of the device, not of any one radio, but every consumer inside the SDK reads it from the per-transport TransportMetrics map: DORS energy scoring, the relay promote/demote policy, the forwarding battery floor, and the telemetry device-capability snapshot all resolve it through device_battery_from_available. This setter is therefore the single host-facing feed, and it is merged into the two snapshot loops that build that map.

level is clamped to 0-100. A transport that reports its own battery level keeps it: the merge fills the field, never overwrites it.

Source

pub fn device_battery(&self) -> (Option<u8>, bool)

Returns the host-reported (battery_level, is_charging) pair, if the platform has published one.

Source

pub fn peer_supports_binary_wire(&self, peer_id: &str) -> bool

Returns whether a peer is recorded as able to decode the binary wire codec (and would therefore be sent binary frames).

Source

pub fn mark_peer_binary_wire(&mut self, peer_id: &str, supported: bool)

Records whether a peer can decode our binary wire frames, learned from its signed key package. Messages addressed to a capable peer are stamped WireCodec::BinaryV1 at send; all others stay JSON.

Source

pub fn mark_peer_nostr_pubkey( &mut self, peer_id: &str, pubkey_hex: Option<&str>, )

Forwards a peer’s advertised Nostr public key to the Nostr transport, so gift wraps addressed to them are sealed to a key only their install holds instead of to the publicly computable bootstrap key.

None means “this peer advertises no Nostr key”, which forgets any key already held rather than leaving it in place. That is what keeps the in-memory copy consistent with the durable record, whose downgrade semantics delete on an empty advertisement: retaining it here instead would keep sealing to a key the peer has stopped claiming, and survive only until the next restart — a divergence with no symptom.

A no-op when the Nostr transport is not installed (the common case — nostr_enabled defaults off). The bound on the underlying map lives in the transport.

Source

pub fn clear_peer_nostr_pubkey(&mut self, peer_id: &str)

Forgets a peer’s Nostr public key, so frames to them revert to the publicly computable bootstrap key.

Used by the unblock clean slate, which declares everything learned about a peer stale. Reverting is the right fallback rather than refusing to send: the bootstrap key is derived from the peer’s user id, so it works whatever install they are on now.

Source

pub fn nostr_public_key(&self) -> Option<String>

This install’s Nostr public key, for advertising in outgoing key packages. None when the Nostr transport is not installed.

Source

pub fn set_nostr_sealing_enabled(&mut self, enabled: bool)

Applies the sealed-envelope kill switch to the Nostr transport.

Source

pub fn set_nostr_cold_contact_enabled(&mut self, enabled: bool)

Applies the cold-contact kill switch to the Nostr transport.

Source

pub fn publish_nostr_key_package( &mut self, slot_id: &str, message: &Message, ) -> Result<()>

Queues a key-package record for publication at slot_id.

A no-op when the Nostr transport is not installed, which is the common case: publication is driven from the engine’s tick, and that tick runs whether or not Nostr is enabled.

Serializes through the transport’s own chokepoint, which yields JSON for an unstamped message — and a published record must never be anything else. The binary codec is negotiated per peer from that peer’s key package, and the reader of this record is by definition a stranger whose key package we have not seen. Emitting binary here would make the record unreadable by exactly the audience it exists for.

Source

pub fn take_failed_nostr_publications(&self) -> Vec<String>

Drains the slot ids whose publication never reached a relay.

Empty when Nostr is not installed, which keeps the caller’s tick free of a transport check it would otherwise need.

Source

pub fn nostr_cold_contact_active(&self) -> bool

Whether the Nostr transport is installed and publishing records.

Source

pub fn set_nostr_username_discovery_enabled(&mut self, enabled: bool)

Enables or disables username discovery on the Nostr transport.

Source

pub fn nostr_discovery_active(&self) -> bool

Whether the Nostr transport is installed and username discovery is on.

Already accounts for the cold-contact coupling: the transport reports false when either switch is off.

Source

pub fn publish_nostr_discovery_record( &mut self, username: Username, payload: Vec<u8>, )

Queues this install’s username claim for publication.

Source

pub fn retract_nostr_discovery_record( &mut self, username: Username, payload: Vec<u8>, )

Queues a retraction of this install’s username claim.

Source

pub fn take_failed_nostr_discovery_publications(&self) -> Vec<String>

Drains the discovery tags whose publication never reached a relay.

Source

pub fn take_confirmed_nostr_discovery_publications(&self) -> Vec<String>

Drains the discovery tags whose publication a relay acknowledged.

Source

pub fn has_nostr_transport(&self) -> bool

Whether a Nostr transport is installed at all.

Distinct from Self::nostr_discovery_active: a retraction is owed whether or not discovery is still switched on, so the engine has to be able to tell “the feature is off” from “there is nothing here that could carry a tombstone”. Without the second, queueing a retraction silently does nothing while the engine records it as done.

Source

pub fn resolve_nostr_username(&self, username: Username) -> ResolveRequest

Requests resolution of the devices claiming username.

A missing Nostr transport reports Disabled, which is what it is from the caller’s side: no query was sent and no event will follow.

Source

pub fn cancel_nostr_username_resolution(&self, username: &Username) -> bool

Withdraws a queued username lookup that was never issued to a relay.

Returns whether one was removed. Called when the engine gives up on a lookup, so the name does not sit in the queue making every later request for it return “already queued” without ever answering.

Source

pub fn set_dors_event_callback( &mut self, callback: Option<Arc<dyn Fn(Event) + Send + Sync>>, )

Sets the callback for DORS decision events (dors_score_updated, dors_transport_selected,

Source

pub fn add_transport( &mut self, transport_type: TransportType, transport: Box<dyn Transport>, )

Adds a transport to the manager.

§Arguments
  • transport_type - Type of transport to add
  • transport - The transport implementation
Source

pub fn send(&mut self, message: &Message) -> Result<()>

Sends a message through the best available transport, with fallback.

DORS selects a primary transport (applying hysteresis, cooldown, and stability checks). If the primary’s send() fails synchronously, the remaining transports are tried in descending score order before returning an error. Each synchronous failure is recorded via record_retry_failure so DORS can adjust future scoring.

§Internet transport — fallback does NOT apply

Internet send() enqueues the message and returns Ok(()) immediately. The actual wire-level outcome is reported asynchronously via the confirm_sent / report_send_failure confirmation loop on InternetTransport. Because send() never fails synchronously, the fallback loop below will not trigger for Internet. If the WebSocket is silently broken (status still Available but sends fail), messages will be enqueued, detected as failures by the confirmation-loop timeout, and counted in DORS metrics — but they are not retried on an alternative transport by this method. Retry/re-routing for those messages is handled by the higher-level outbox retry mechanism.

Source

pub fn send_via_transport( &mut self, message: &Message, transport_type: TransportType, ) -> Result<()>

Sends a message via a specific transport, bypassing DORS selection.

§Arguments
  • message - The message to send
  • transport_type - The transport to use
§Returns

Returns Ok(()) if sent successfully, Err otherwise.

Source

pub fn mesh_neighbors(&self) -> Vec<MeshNeighbor>

Lists every peer reachable over a direct mesh link, with the transport that link runs on.

Only the peer-to-peer carriers are consulted: a mesh neighbor is one we can hand a frame to over our own radio, which is what makes it a candidate next hop. Infrastructure carriers (Internet, Nostr, Reticulum) reach peers through something else, so they report no links and appear here as nothing — a message routed through them is not taking a mesh hop, it is leaving the mesh.

A peer visible on more than one carrier is reported once, on the first carrier that claims it; Self::send_to_neighbor resolves the same way, so the pair stay consistent.

Source

pub fn mesh_transport_for(&self, peer_id: &str) -> Option<TransportType>

The mesh carrier holding a live link straight to peer_id, if any.

Ordered by mesh-carrier preference, so a peer reachable over both answers with the higher-bandwidth carrier. This is ground truth rather than a claim: it is read from the transport’s live link view at the moment it is asked, never remembered.

Source

pub fn available_infrastructure_carriers(&self) -> Vec<TransportType>

Every available carrier that does its own routing.

The enumerated form of Self::has_infrastructure_carrier, for callers that hold a per-recipient fact and must ask each carrier separately rather than accepting “one of them is up” for every recipient.

Source

pub fn can_reach_without_carrying(&self, peer_id: &str) -> bool

Whether a frame for peer_id can plausibly arrive without being carried by other devices.

This exists because a send returning Ok is not evidence of reachability. Only BLE refuses a recipient it holds no link to; Wi-Fi Direct and Reticulum enqueue for any recipient and report success, so a frame handed to them for someone out of range is queued for a link that will never drain — reported as sent, silently swallowed. Anything that decides “the mesh has to carry this” from a send failure therefore never fires on a device where one of those carriers is up. Asking this instead keeps that decision on facts we can check.

Two ways the answer is yes:

  • An infrastructure carrier is available. Internet, Nostr and Reticulum do their own routing and reach peers we hold no radio link to, so a direct send is a real delivery attempt. (Reticulum counts here because it is a routing network in its own right — its Ok means “accepted for routing”, which is as much as any relay-style carrier promises.)
  • The peer is one of our own mesh neighbors, so a mesh carrier can hand the frame straight over.

Checked in that order so the common online case costs a status scan and never enumerates links.

This answer is deliberately peer-blind on its first arm, and that is a real limit rather than an oversight: an infrastructure carrier being up says nothing about whether this recipient is on it. Callers that hold a peer-specific fact must not settle for this answer — the relay’s own recipient_unreachable verdict is exactly such a fact, and the park it drives offers the frame to the mesh regardless of what this returns (see park_unreachable_dm).

Source

pub fn has_infrastructure_carrier(&self) -> bool

Whether any carrier that does its own routing is available.

Peer-blind by nature: these carriers reach peers we hold no radio link to, so there is no per-peer link to consult. Note the status is bridge-reported and means “the platform says this carrier is up”, not “the relay connection is authenticated” — a distinction that matters wherever this stands in for reachability.

Source

pub fn mesh_can_address(&self, peer_id: &str) -> bool

Whether a mesh carrier holds a live link straight to peer_id.

The peer-specific half of Self::can_reach_without_carrying, split out because callers that already know infrastructure is up still need to ask whether the mesh can hand a frame over without anyone carrying it.

Source

pub fn is_mesh_transport(transport_type: TransportType) -> bool

Whether transport_type is a short-range carrier that can only address peers it holds a live link to — as opposed to an infrastructure carrier that does its own routing.

A frame that arrived over one of these travelled either from a neighbor or through them, which is what makes it evidence about the route back.

Source

pub fn can_address_via( &self, transport_type: TransportType, peer_id: &str, ) -> bool

Whether transport_type can actually put a frame in front of peer_id.

The narrower question Self::can_reach_without_carrying answers across every carrier, asked of one. It exists for the same reason: a transport returning Ok is not evidence the frame can arrive. A mesh carrier can only address a peer it holds a live link to, and Wi-Fi Direct enqueues for any recipient regardless — so a frame handed to it for someone several hops away is queued for a link that never drains. Infrastructure carriers do their own routing, so for them the answer is yes whenever they are available.

Callers that would otherwise trust a preferred transport — replying on the link a message arrived over, above all — must ask this first, or the reply dies on exactly the multi-hop path that made forwarding necessary.

Source

pub fn send_to_neighbor( &self, peer_id: &str, message: &Message, ) -> Result<TransportType>

Hands message to a specific mesh neighbor, whatever the message’s own recipient is.

This is the forwarding primitive: the frame crosses one link, to the peer named by peer_id. Because that peer is the physical target, the binary wire codec is negotiated against its capabilities rather than the recipient’s — stamping a forwarded frame binary because the distant recipient supports it could put bytes a neighbor cannot decode onto that neighbor’s link.

Returns the transport the frame went out on.

Source

pub fn receive(&self) -> Result<Option<(TransportType, Message)>>

Attempts to receive a message from any transport.

§Returns

Returns Ok(Some((TransportType, Message))) if a message was received, Ok(None) if no message available.

Source

pub fn get_available_transports( &self, ) -> HashMap<TransportType, TransportMetrics>

Gets metrics for all available transports.

§Returns

Returns a map of transport type to metrics.

Source

pub fn current_transport(&self) -> Option<TransportType>

Gets the current active transport type.

Source

pub fn get_all_transport_statuses( &self, ) -> HashMap<TransportType, TransportStatus>

Returns the current status of every registered transport, including those not currently TransportStatus::Available.

Used by the telemetry aggregator to detect state transitions; unlike TransportManager::get_available_transports, this only reads each transport’s status with no metrics work.

Source

pub fn snapshot_status_and_available( &self, ) -> (HashMap<TransportType, TransportStatus>, HashMap<TransportType, TransportMetrics>)

Returns the per-transport status map AND the available-only metrics map in a single pass.

Equivalent to calling Self::get_all_transport_statuses and Self::get_available_transports back-to-back, but reads each transport’s status once instead of twice. Used by the per-tick telemetry aggregator.

Source

pub fn start(&mut self) -> Result<()>

Starts all transports.

Source

pub fn stop(&mut self) -> Result<()>

Stops all transports.

Source

pub fn get_transport( &self, transport_type: TransportType, ) -> Option<Arc<dyn Transport>>

Gets a shared handle to a specific transport.

Source

pub fn remove_transport(&mut self, transport_type: TransportType)

Removes a transport from the manager.

§Arguments
  • transport_type - Type of transport to remove
Source

pub fn get_active_transports(&self) -> Vec<TransportType>

Gets a list of all active transport types.

§Returns

Returns a vector of transport types that are currently added to the manager.

Source

pub fn should_escalate_to_wifi(&self) -> bool

Checks if DORS suggests escalating from BLE to WiFi Direct.

Source

pub fn record_retry_failure(&mut self, transport_type: TransportType)

Records a retry failure for the given transport.

Source

pub fn reset_retry_count(&mut self, transport_type: TransportType)

Resets retry count for the given transport after successful delivery.

Source

pub fn record_delivery_success( &mut self, transport_type: TransportType, latency_ms: u32, hop_count: u8, )

Records a successful end-to-end delivery for the given transport.

Source

pub fn record_delivery_failure(&mut self, transport_type: TransportType)

Records a delivery failure (after exhausting retries) for the given transport.

Source

pub fn update_selector_config(&mut self, config: DorsConfig)

Updates the DORS selector configuration at runtime, preserving accumulated state (transport history, retry counts, signal tracking).

Source

pub fn selector_config(&self) -> &DorsConfig

Returns the DORS configuration transport scoring runs against.

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

impl<T> Classify for T

Source§

type Classified = T

Source§

fn classify(self) -> T

Source§

impl<T> Declassify for T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

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

Source§

fn fg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

fn bg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

fn attr(&self, value: Attribute) -> Painted<&T>

Enables the styling Attribute value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

fn quirk(&self, value: Quirk) -> Painted<&T>

Enables the yansi Quirk value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
Source§

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

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

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

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

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

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

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

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

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

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

👎Deprecated since 1.0.1:

renamed to resetting() due to conflicts with Vec::clear(). The clear() method will be removed in a future release.

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

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

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

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

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

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

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

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

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

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

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

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

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

Create a new Painted with a default Style. Read more
Source§

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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