Skip to main content

Service

Struct Service 

Source
pub struct Service {
    services: Arc<OnceServices>,
    db: Data,
}

Fields§

§services: Arc<OnceServices>§db: Data

Implementations§

Source§

impl Service

Source

pub async fn set_dehydrated_device( &self, user_id: &UserId, request: Request, ) -> Result

Creates or recreates the user’s dehydrated device.

Source§

impl Service

Source

pub(super) async fn remove_dehydrated_device( &self, user_id: &UserId, maybe_device_id: Option<&DeviceId>, ) -> Result<OwnedDeviceId>

Removes a user’s dehydrated device.

Calling this directly will remove the dehydrated data but leak the frontage device. Thus this is called by the regular device interface such that the dehydrated data will not leak instead.

If device_id is given, the user’s dehydrated device must match or this is a no-op, but an Err is still returned to indicate that. Otherwise returns the removed dehydrated device_id.

Source§

impl Service

Source

pub async fn get_dehydrated_device_id( &self, user_id: &UserId, ) -> Result<OwnedDeviceId>

Get the device_id of the user’s dehydrated device.

Source§

impl Service

Source

pub async fn get_dehydrated_device( &self, user_id: &UserId, ) -> Result<DehydratedDevice>

Get the dehydrated device private data

Source§

impl Service

Source

pub async fn create_device( &self, user_id: &UserId, device_id: Option<&DeviceId>, __arg3: (Option<&str>, Option<Duration>), refresh_token: Option<&str>, initial_device_display_name: Option<&str>, client_ip: Option<IpAddr>, ) -> Result<OwnedDeviceId>

Adds a new device to a user.

Source§

impl Service

Source

pub async fn remove_device(&self, user_id: &UserId, device_id: &DeviceId)

Removes a device from a user.

Source§

impl Service

Source

pub fn all_device_ids<'a>( &'a self, user_id: &'a UserId, ) -> impl Stream<Item = &DeviceId> + Send + 'a

Returns an iterator over all device ids of this user.

Source§

impl Service

Source

pub async fn find_from_token( &self, token: &str, ) -> Result<(OwnedUserId, OwnedDeviceId, Option<SystemTime>)>

Find out which user an access or refresh token belongs to.

Source§

impl Service

Source

pub async fn remove_tokens(&self, user_id: &UserId, device_id: &DeviceId)

Source§

impl Service

Source

pub async fn set_access_token( &self, user_id: &UserId, device_id: &DeviceId, access_token: &str, expires_in: Option<Duration>, refresh_token: Option<&str>, ) -> Result

Replaces the access token of one device.

Source§

impl Service

Source

pub async fn remove_access_token( &self, user_id: &UserId, device_id: &DeviceId, ) -> Result

Revoke the access token without deleting the device. Take care to not leave dangling devices if using this method.

Source§

impl Service

Source

pub async fn get_access_token( &self, user_id: &UserId, device_id: &DeviceId, ) -> Result<String>

Source§

impl Service

Source

pub fn generate_access_token(&self, expires: bool) -> (String, Option<Duration>)

Source§

impl Service

Source

pub async fn set_refresh_token( &self, user_id: &UserId, device_id: &DeviceId, refresh_token: &str, ) -> Result

Replaces the refresh token of one device.

Source§

impl Service

Source

async fn find_refresh_token_expires_at( &self, user_id: &UserId, device_id: &DeviceId, ) -> Option<SystemTime>

Look up the expiry stored alongside the current refresh token for this device, if one is recorded. Pre-rotation entries carry no expiry and return None.

Source§

impl Service

Source

pub async fn remove_refresh_token( &self, user_id: &UserId, device_id: &DeviceId, ) -> Result

Revoke the refresh token without deleting the device. Take care to not leave dangling devices if using this method.

Source§

impl Service

Source

pub async fn get_refresh_token( &self, user_id: &UserId, device_id: &DeviceId, ) -> Result<String>

Source§

impl Service

Source

pub fn add_to_device_event( &self, sender: &UserId, target_user_id: &UserId, target_device_id: &DeviceId, event_type: &str, content: &Value, )

Source§

impl Service

Source

pub fn get_to_device_events<'a>( &'a self, user_id: &'a UserId, device_id: &'a DeviceId, since: Option<u64>, to: Option<u64>, ) -> impl Stream<Item = (u64, Raw<AnyToDeviceEvent>)> + Send + 'a

Source§

impl Service

Source

pub async fn remove_to_device_events<Until>( &self, user_id: &UserId, device_id: &DeviceId, until: Until, )
where Until: Into<Option<u64>> + Send,

Source§

impl Service

Source

pub async fn update_device_last_seen( &self, user_id: &UserId, device_id: &DeviceId, last_seen_ip: Option<IpAddr>, last_seen_ts: Option<MilliSecondsSinceUnixEpoch>, ) -> Result

Source§

impl Service

Source

pub fn put_device_metadata( &self, user_id: &UserId, notify: bool, device: &Device, )

Source§

impl Service

Source

pub async fn get_device_metadata( &self, user_id: &UserId, device_id: &DeviceId, ) -> Result<Device>

Get device metadata.

Source§

impl Service

Source

pub async fn device_exists( &self, user_id: &UserId, device_id: &DeviceId, ) -> bool

Source§

impl Service

Source

pub async fn is_oidc_device( &self, user_id: &UserId, device_id: &DeviceId, ) -> bool

Source§

impl Service

Source

pub async fn get_oidc_device_idp( &self, user_id: &UserId, device_id: &DeviceId, ) -> Option<String>

Returns the IdP that originally authenticated this device, if known. Returns None for devices predating the idp_id field or non-OIDC devices.

Source§

impl Service

Source

pub fn mark_oidc_device( &self, user_id: &UserId, device_id: &DeviceId, idp_id: &str, )

Source§

impl Service

Source

pub fn allow_cross_signing_replacement(&self, user_id: &UserId) -> SystemTime

Allow cross-signing key replacement without UIAA for the next 10 minutes. Returns the expiry timestamp in milliseconds.

Source§

impl Service

Source

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

Check if the user is allowed to replace cross-signing keys without UIAA.

Source§

impl Service

Source

pub async fn get_devicelist_version(&self, user_id: &UserId) -> Result<u64>

Source§

impl Service

Source

pub fn all_devices_metadata<'a>( &'a self, user_id: &'a UserId, ) -> impl Stream<Item = Device> + Send + 'a

Source§

impl Service

Source

pub async fn add_one_time_keys<'a, Keys>( &self, user_id: &UserId, device_id: &DeviceId, keys: Keys, ) -> Result
where Keys: Iterator<Item = (&'a OneTimeKeyId, &'a Raw<OneTimeKey>)> + Send + 'a,

Source§

impl Service

Source

pub async fn add_one_time_key( &self, user_id: &UserId, device_id: &DeviceId, one_time_key_key: &KeyId<OneTimeKeyAlgorithm, OneTimeKeyName>, one_time_key_value: &Raw<OneTimeKey>, ) -> Result

Source§

impl Service

Source

pub async fn add_fallback_keys<'a, Keys>( &self, user_id: &UserId, device_id: &DeviceId, keys: Keys, ) -> Result
where Keys: Iterator<Item = (&'a OneTimeKeyId, &'a Raw<OneTimeKey>)> + Send + 'a,

Source§

impl Service

Source

pub async fn add_fallback_key( &self, user_id: &UserId, device_id: &DeviceId, one_time_key_key: &KeyId<OneTimeKeyAlgorithm, OneTimeKeyName>, one_time_key_value: &Raw<OneTimeKey>, ) -> Result

Source§

impl Service

Source

pub async fn take_fallback_key( &self, user_id: &UserId, device_id: &DeviceId, algorithm: &OneTimeKeyAlgorithm, ) -> Result<(OwnedKeyId<OneTimeKeyAlgorithm, OneTimeKeyName>, Raw<OneTimeKey>)>

Source§

impl Service

Source

pub fn unused_fallback_key_algorithms<'a>( &'a self, user_id: &'a UserId, device_id: &'a DeviceId, ) -> impl Stream<Item = OneTimeKeyAlgorithm> + Send + 'a

Source§

impl Service

Source

pub async fn last_one_time_keys_update(&self, user_id: &UserId) -> u64

Source§

impl Service

Source

pub async fn take_one_time_key( &self, user_id: &UserId, device_id: &DeviceId, key_algorithm: &OneTimeKeyAlgorithm, ) -> Result<(OwnedKeyId<OneTimeKeyAlgorithm, OneTimeKeyName>, Raw<OneTimeKey>)>

Source§

impl Service

Source

pub async fn count_one_time_keys( &self, user_id: &UserId, device_id: &DeviceId, ) -> BTreeMap<OneTimeKeyAlgorithm, UInt>

Source§

impl Service

Source

pub async fn prune_one_time_keys( &self, user_id: &UserId, device_id: &DeviceId, excess: usize, )

MSC4225: drop the excess oldest rows for this (user, device). Forward iteration over the prefix runs in count_be ascending order, so take(excess) yields the earliest-uploaded rows.

Source§

impl Service

Source

pub async fn add_device_keys( &self, user_id: &UserId, device_id: &DeviceId, device_keys: &Raw<DeviceKeys>, )

Source§

impl Service

Source

pub async fn add_cross_signing_keys( &self, user_id: &UserId, master_key: &Option<Raw<CrossSigningKey>>, self_signing_key: &Option<Raw<CrossSigningKey>>, user_signing_key: &Option<Raw<CrossSigningKey>>, notify: bool, ) -> Result

Source§

impl Service

Source

pub async fn sign_key( &self, target_id: &UserId, key_id: &str, signature: (String, String), sender_id: &UserId, ) -> Result

Source§

impl Service

Source

pub fn keys_changed<'a>( &'a self, user_id: &'a UserId, from: u64, to: Option<u64>, ) -> impl Stream<Item = &UserId> + Send + 'a

Source§

impl Service

Source

pub fn room_keys_changed<'a>( &'a self, room_id: &'a RoomId, from: u64, to: Option<u64>, ) -> impl Stream<Item = (&UserId, u64)> + Send + 'a

Source§

impl Service

Source

fn keys_changed_user_or_room<'a>( &'a self, user_or_room_id: &'a str, from: u64, to: Option<u64>, ) -> impl Stream<Item = (&UserId, u64)> + Send + 'a

Source§

impl Service

Source

pub async fn mark_device_key_update(&self, user_id: &UserId)

Source§

impl Service

Source

pub async fn get_device_keys<'a>( &'a self, user_id: &'a UserId, device_id: &DeviceId, ) -> Result<Raw<DeviceKeys>>

Source§

impl Service

Source

pub async fn get_key<F>( &self, key_id: &[u8], sender_user: Option<&UserId>, user_id: &UserId, allowed_signatures: &F, ) -> Result<Raw<CrossSigningKey>>
where F: Fn(&UserId) -> bool + Send + Sync,

Source§

impl Service

Source

pub async fn get_master_key<F>( &self, sender_user: Option<&UserId>, user_id: &UserId, allowed_signatures: &F, ) -> Result<Raw<CrossSigningKey>>
where F: Fn(&UserId) -> bool + Send + Sync,

Source§

impl Service

Source

pub async fn get_self_signing_key<F>( &self, sender_user: Option<&UserId>, user_id: &UserId, allowed_signatures: &F, ) -> Result<Raw<CrossSigningKey>>
where F: Fn(&UserId) -> bool + Send + Sync,

Source§

impl Service

Source

pub async fn get_user_signing_key( &self, user_id: &UserId, ) -> Result<Raw<CrossSigningKey>>

Source§

impl Service

Source

pub async fn search_ldap(&self, user_id: &UserId) -> Result<Vec<(String, bool)>>

Performs a LDAP search for the given user.

Returns the list of matching users, with a boolean for each result set to true if the user is an admin.

Source§

impl Service

Source

pub async fn auth_ldap(&self, user_dn: &str, password: &str) -> Result

Source§

impl Service

Source

pub async fn update_displayname( &self, user_id: &UserId, displayname: Option<&str>, rooms: &[OwnedRoomId], propagation: Propagation, )

Source§

impl Service

Source

pub fn set_displayname(&self, user_id: &UserId, displayname: Option<&str>)

Sets a new displayname or removes it if displayname is None. You still need to notify all rooms of this change.

Source§

impl Service

Source

pub async fn displayname(&self, user_id: &UserId) -> Result<String>

Returns the displayname of a user on this homeserver.

Source§

impl Service

Source

pub async fn update_avatar_url( &self, user_id: &UserId, avatar_url: Option<&MxcUri>, blurhash: Option<&str>, rooms: &[OwnedRoomId], propagation: Propagation, )

Source§

impl Service

Source

pub fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option<&MxcUri>)

Sets a new avatar_url or removes it if avatar_url is None.

Source§

impl Service

Source

pub async fn avatar_url(&self, user_id: &UserId) -> Result<OwnedMxcUri>

Get the avatar_url of a user.

Source§

impl Service

Source

pub fn set_blurhash(&self, user_id: &UserId, blurhash: Option<&str>)

Sets a new avatar_url or removes it if avatar_url is None.

Source§

impl Service

Source

pub async fn blurhash(&self, user_id: &UserId) -> Result<String>

Get the blurhash of a user.

Source§

impl Service

Source

pub fn set_timezone(&self, user_id: &UserId, timezone: Option<&str>)

Sets a new timezone or removes it if timezone is None.

Source§

impl Service

Source

pub async fn timezone(&self, user_id: &UserId) -> Result<String>

Get the timezone of a user.

Source§

impl Service

Source

pub fn all_profile_keys<'a>( &'a self, user_id: &'a UserId, ) -> impl Stream<Item = (String, Raw<ProfileFieldValue>)> + 'a + Send

Gets all the user’s profile keys and values in an iterator

Source§

impl Service

Source

pub fn set_profile_key( &self, user_id: &UserId, profile_key: &str, profile_key_value: Option<&Value>, )

Sets a new profile key value, removes the key if value is None

Source§

impl Service

Source

pub async fn profile_key( &self, user_id: &UserId, profile_key: &str, ) -> Result<Raw<ProfileFieldValue>>

Gets a specific user profile key

Source§

impl Service

Source

async fn member_displayname( &self, room_id: &RoomId, user_id: &UserId, ) -> Option<String>

Current per-room displayname for the user, or None if the room has no member event for them.

Source§

impl Service

Source

async fn member_avatar_url( &self, room_id: &RoomId, user_id: &UserId, ) -> Option<OwnedMxcUri>

Current per-room avatar_url for the user, or None if the room has no member event for them.

Source§

impl Service

Source

pub async fn full_register(&self, __arg1: Register<'_>) -> Result

Fully register a local user

Returns a device id and access token for the registered user

Source§

impl Service

Source

pub async fn user_is_ignored( &self, sender_user: &UserId, recipient_user: &UserId, ) -> bool

Returns true/false based on whether the recipient/receiving user has blocked the sender

Source

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

MSC4380: m.invite_permission_config.default_action == "block".

Source

pub async fn create( &self, user_id: &UserId, password: Option<&str>, origin: Option<&str>, ) -> Result

Create a new user account on this homeserver.

User origin is by default “password” (meaning that it will login using its user_id/password). Users with other origins (currently only “ldap” is available) have special login processes.

Source

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

Deactivate account

Source

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

Check if a user has an account on this homeserver.

Source

pub async fn is_deactivated(&self, user_id: &UserId) -> Result<bool>

Check if account is deactivated

Source

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

Check if account is active, infallible

Source

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

Check if account is active, infallible

Source

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

MSC3823: account is suspended (read-mostly mode, sessions retained).

Source

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

MSC3939: account is locked (401 + soft_logout, sessions retained).

Source

pub async fn get_suspension(&self, user_id: &UserId) -> Option<Moderation>

MSC3823: forensic record for the active suspension, if any.

Source

pub async fn get_lock(&self, user_id: &UserId) -> Option<Moderation>

MSC3939: forensic record for the active lock, if any.

Source

pub fn set_suspended(&self, user_id: &UserId, by: &UserId)

Source

pub fn clear_suspended(&self, user_id: &UserId)

Source

pub fn set_locked(&self, user_id: &UserId, by: &UserId)

Source

pub fn clear_locked(&self, user_id: &UserId)

Source

pub async fn count(&self) -> usize

Returns the number of users registered on this server.

Source

pub fn stream(&self) -> impl Stream<Item = &UserId> + Send

Returns an iterator over all users on this homeserver.

Source

pub fn list_local_users(&self) -> impl Stream<Item = &UserId> + Send + '_

Returns a list of local users as list of usernames.

A user account is considered local if the length of it’s password is greater then zero.

Source

pub async fn origin(&self, user_id: &UserId) -> Result<String>

Returns the origin of the user (password/LDAP/…).

Source

pub async fn has_password(&self, user_id: &UserId) -> Result<bool>

Returns whether the user has a password. Disabled accounts and registrations setting a sentinel password will return false here.

Source

pub async fn password_hash(&self, user_id: &UserId) -> Result<String>

Returns the password hash for the given user.

Source

pub async fn set_password( &self, user_id: &UserId, password: Option<&str>, ) -> Result

Hash and set the user’s password to the Argon2 hash

Source

pub fn create_filter( &self, user_id: &UserId, filter: &FilterDefinition, ) -> String

Creates a new sync filter. Returns the filter id.

Source

pub async fn get_filter( &self, user_id: &UserId, filter_id: &str, ) -> Result<FilterDefinition>

Source

pub fn create_openid_token(&self, user_id: &UserId, token: &str) -> Result<u64>

Creates an OpenID token, which can be used to prove that a user has access to an account (primarily for integrations)

Source

pub async fn find_from_openid_token(&self, token: &str) -> Result<OwnedUserId>

Find out which user an OpenID access token belongs to.

Source

pub fn create_login_token(&self, user_id: &UserId, token: &str) -> u64

Creates a short-lived login token, which can be used to log in using the m.login.token mechanism.

Source

pub async fn peek_login_token(&self, token: &str) -> Result<OwnedUserId>

Verify a login token is valid and return its owner without consuming it. Unlike find_from_login_token, the token remains in the database after this call and can still be consumed later.

Source

pub async fn find_from_login_token(&self, token: &str) -> Result<OwnedUserId>

Find out which user a login token belongs to. Removes the token to prevent double-use attacks.

Source

async fn update_all_rooms<'a, S>(&self, user_id: &UserId, rooms: S)
where S: Stream<Item = (PduBuilder, &'a OwnedRoomId)> + Send,

Trait Implementations§

Source§

impl Service for Service

Source§

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

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

fn name(&self) -> &str

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

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

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

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

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

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

Clear any caches or similar runtime state.
Source§

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

Memory usage report in a markdown string.
Source§

fn unconstrained(&self) -> bool

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> DropFlavorWrapper<T> for T

§

type Flavor = MayDrop

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

impl<T> ExpectInto for T

Source§

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

Source§

impl<T> Expected for T

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

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> 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: 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: 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,

Source§

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

Source§

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

Source§

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

Source§

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

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
§

impl<T> JsonCastable<CanonicalJsonValue> for T

§

impl<T> JsonCastable<Value> for T