Struct aws_sdk_sts::config::Builder

source ·
pub struct Builder { /* private fields */ }
Expand description

Builder for creating a Config.

Implementations§

source§

impl Builder

source

pub fn new() -> Self

Constructs a config builder.

source

pub fn stalled_stream_protection( self, stalled_stream_protection_config: StalledStreamProtectionConfig, ) -> Self

Set the StalledStreamProtectionConfig to configure protection for stalled streams.

source

pub fn set_stalled_stream_protection( &mut self, stalled_stream_protection_config: Option<StalledStreamProtectionConfig>, ) -> &mut Self

Set the StalledStreamProtectionConfig to configure protection for stalled streams.

source

pub fn http_client(self, http_client: impl HttpClient + 'static) -> Self

Sets the HTTP client to use when making requests.

§Examples
use std::time::Duration;
use aws_sdk_sts::config::Config;
use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;

let https_connector = hyper_rustls::HttpsConnectorBuilder::new()
    .with_webpki_roots()
    .https_only()
    .enable_http1()
    .enable_http2()
    .build();
let hyper_client = HyperClientBuilder::new().build(https_connector);

// This connector can then be given to a generated service Config
let config = my_service_client::Config::builder()
    .endpoint_url("https://example.com")
    .http_client(hyper_client)
    .build();
let client = my_service_client::Client::from_conf(config);
source

pub fn set_http_client( &mut self, http_client: Option<SharedHttpClient>, ) -> &mut Self

Sets the HTTP client to use when making requests.

§Examples
use std::time::Duration;
use aws_sdk_sts::config::{Builder, Config};
use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;

fn override_http_client(builder: &mut Builder) {
    let https_connector = hyper_rustls::HttpsConnectorBuilder::new()
        .with_webpki_roots()
        .https_only()
        .enable_http1()
        .enable_http2()
        .build();
    let hyper_client = HyperClientBuilder::new().build(https_connector);
    builder.set_http_client(Some(hyper_client));
}

let mut builder = aws_sdk_sts::Config::builder();
override_http_client(&mut builder);
let config = builder.build();
source

pub fn endpoint_resolver( self, endpoint_resolver: impl ResolveEndpoint + 'static, ) -> Self

Sets the endpoint resolver to use when making requests.

When unset, the client will used a generated endpoint resolver based on the endpoint resolution rules for aws_sdk_sts.

Note: setting an endpoint resolver will replace any endpoint URL that has been set. This method accepts an endpoint resolver specific to this service. If you want to provide a shared endpoint resolver, use Self::set_endpoint_resolver.

§Examples

Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production.

use aws_sdk_sts::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint};
#[derive(Debug)]
struct StageResolver { stage: String }
impl ResolveEndpoint for StageResolver {
    fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> {
        let stage = &self.stage;
        EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build()))
    }
}
let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() };
let config = aws_sdk_sts::Config::builder().endpoint_resolver(resolver).build();
let client = aws_sdk_sts::Client::from_conf(config);
source

pub fn set_endpoint_resolver( &mut self, endpoint_resolver: Option<SharedEndpointResolver>, ) -> &mut Self

Sets the endpoint resolver to use when making requests.

When unset, the client will used a generated endpoint resolver based on the endpoint resolution rules for aws_sdk_sts.

source

pub fn retry_config(self, retry_config: RetryConfig) -> Self

Set the retry_config for the builder

§Examples
use aws_sdk_sts::config::Config;
use aws_sdk_sts::config::retry::RetryConfig;

let retry_config = RetryConfig::standard().with_max_attempts(5);
let config = Config::builder().retry_config(retry_config).build();
source

pub fn set_retry_config( &mut self, retry_config: Option<RetryConfig>, ) -> &mut Self

Set the retry_config for the builder

§Examples
use aws_sdk_sts::config::{Builder, Config};
use aws_sdk_sts::config::retry::RetryConfig;

fn disable_retries(builder: &mut Builder) {
    let retry_config = RetryConfig::standard().with_max_attempts(1);
    builder.set_retry_config(Some(retry_config));
}

let mut builder = Config::builder();
disable_retries(&mut builder);
let config = builder.build();
source

pub fn sleep_impl(self, sleep_impl: impl AsyncSleep + 'static) -> Self

Set the sleep_impl for the builder

§Examples
use aws_sdk_sts::config::{AsyncSleep, Config, SharedAsyncSleep, Sleep};

#[derive(Debug)]
pub struct ForeverSleep;

impl AsyncSleep for ForeverSleep {
    fn sleep(&self, duration: std::time::Duration) -> Sleep {
        Sleep::new(std::future::pending())
    }
}

let sleep_impl = SharedAsyncSleep::new(ForeverSleep);
let config = Config::builder().sleep_impl(sleep_impl).build();
source

pub fn set_sleep_impl( &mut self, sleep_impl: Option<SharedAsyncSleep>, ) -> &mut Self

Set the sleep_impl for the builder

§Examples
use aws_sdk_sts::config::{AsyncSleep, Builder, Config, SharedAsyncSleep, Sleep};

#[derive(Debug)]
pub struct ForeverSleep;

impl AsyncSleep for ForeverSleep {
    fn sleep(&self, duration: std::time::Duration) -> Sleep {
        Sleep::new(std::future::pending())
    }
}

fn set_never_ending_sleep_impl(builder: &mut Builder) {
    let sleep_impl = SharedAsyncSleep::new(ForeverSleep);
    builder.set_sleep_impl(Some(sleep_impl));
}

let mut builder = Config::builder();
set_never_ending_sleep_impl(&mut builder);
let config = builder.build();
source

pub fn timeout_config(self, timeout_config: TimeoutConfig) -> Self

Set the timeout_config for the builder

§Examples
use aws_sdk_sts::config::Config;
use aws_sdk_sts::config::timeout::TimeoutConfig;

let timeout_config = TimeoutConfig::builder()
    .operation_attempt_timeout(Duration::from_secs(1))
    .build();
let config = Config::builder().timeout_config(timeout_config).build();
source

pub fn set_timeout_config( &mut self, timeout_config: Option<TimeoutConfig>, ) -> &mut Self

Set the timeout_config for the builder.

Setting this to None has no effect if another source of configuration has set timeouts. If you are attempting to disable timeouts, use TimeoutConfig::disabled

§Examples
use aws_sdk_sts::config::{Builder, Config};
use aws_sdk_sts::config::timeout::TimeoutConfig;

fn set_request_timeout(builder: &mut Builder) {
    let timeout_config = TimeoutConfig::builder()
        .operation_attempt_timeout(Duration::from_secs(1))
        .build();
    builder.set_timeout_config(Some(timeout_config));
}

let mut builder = Config::builder();
set_request_timeout(&mut builder);
let config = builder.build();
source

pub fn retry_partition(self, retry_partition: RetryPartition) -> Self

Set the partition for retry-related state. When clients share a retry partition, they will also share things like token buckets and client rate limiters. By default, all clients for the same service will share a partition.

source

pub fn set_retry_partition( &mut self, retry_partition: Option<RetryPartition>, ) -> &mut Self

Set the partition for retry-related state. When clients share a retry partition, they will also share things like token buckets and client rate limiters. By default, all clients for the same service will share a partition.

source

pub fn identity_cache( self, identity_cache: impl ResolveCachedIdentity + 'static, ) -> Self

Set the identity cache for auth.

The identity cache defaults to a lazy caching implementation that will resolve an identity when it is requested, and place it in the cache thereafter. Subsequent requests will take the value from the cache while it is still valid. Once it expires, the next request will result in refreshing the identity.

This configuration allows you to disable or change the default caching mechanism. To use a custom caching mechanism, implement the ResolveCachedIdentity trait and pass that implementation into this function.

§Examples

Disabling identity caching:

use aws_sdk_sts::config::IdentityCache;

let config = aws_sdk_sts::Config::builder()
    .identity_cache(IdentityCache::no_cache())
    // ...
    .build();
let client = aws_sdk_sts::Client::from_conf(config);

Customizing lazy caching:

use aws_sdk_sts::config::IdentityCache;
use std::time::Duration;

let config = aws_sdk_sts::Config::builder()
    .identity_cache(
        IdentityCache::lazy()
            // change the load timeout to 10 seconds
            .load_timeout(Duration::from_secs(10))
            .build()
    )
    // ...
    .build();
let client = aws_sdk_sts::Client::from_conf(config);
source

pub fn set_identity_cache( &mut self, identity_cache: impl ResolveCachedIdentity + 'static, ) -> &mut Self

Set the identity cache for auth.

The identity cache defaults to a lazy caching implementation that will resolve an identity when it is requested, and place it in the cache thereafter. Subsequent requests will take the value from the cache while it is still valid. Once it expires, the next request will result in refreshing the identity.

This configuration allows you to disable or change the default caching mechanism. To use a custom caching mechanism, implement the ResolveCachedIdentity trait and pass that implementation into this function.

§Examples

Disabling identity caching:

use aws_sdk_sts::config::IdentityCache;

let config = aws_sdk_sts::Config::builder()
    .identity_cache(IdentityCache::no_cache())
    // ...
    .build();
let client = aws_sdk_sts::Client::from_conf(config);

Customizing lazy caching:

use aws_sdk_sts::config::IdentityCache;
use std::time::Duration;

let config = aws_sdk_sts::Config::builder()
    .identity_cache(
        IdentityCache::lazy()
            // change the load timeout to 10 seconds
            .load_timeout(Duration::from_secs(10))
            .build()
    )
    // ...
    .build();
let client = aws_sdk_sts::Client::from_conf(config);
source

pub fn interceptor(self, interceptor: impl Intercept + 'static) -> Self

Add an interceptor that runs at specific stages of the request execution pipeline.

Interceptors targeted at a certain stage are executed according to the pre-defined priority. The SDK provides a default set of interceptors. An interceptor configured by this method will run after those default interceptors.

§Examples
use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
use aws_smithy_types::config_bag::ConfigBag;
use aws_sdk_sts::config::Config;

fn base_url() -> String {
    // ...
}

#[derive(Debug)]
pub struct UriModifierInterceptor;
impl Intercept for UriModifierInterceptor {
    fn modify_before_signing(
        &self,
        context: &mut InterceptorContext<BeforeTransmit>,
        _cfg: &mut ConfigBag,
    ) -> Result<(), aws_smithy_runtime_api::client::interceptors::BoxError> {
        let request = context.request_mut();
        let uri = format!("{}{}", base_url(), request.uri().path());
        *request.uri_mut() = uri.parse()?;

        Ok(())
    }
}

let config = Config::builder()
    .interceptor(UriModifierInterceptor)
    .build();
source

pub fn push_interceptor(&mut self, interceptor: SharedInterceptor) -> &mut Self

Add a SharedInterceptor that runs at specific stages of the request execution pipeline.

Interceptors targeted at a certain stage are executed according to the pre-defined priority. The SDK provides a default set of interceptors. An interceptor configured by this method will run after those default interceptors.

§Examples
use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext, SharedInterceptor};
use aws_smithy_types::config_bag::ConfigBag;
use aws_sdk_sts::config::{Builder, Config};

fn base_url() -> String {
    // ...
}

fn modify_request_uri(builder: &mut Builder) {
    #[derive(Debug)]
    pub struct UriModifierInterceptor;
    impl Intercept for UriModifierInterceptor {
        fn modify_before_signing(
            &self,
            context: &mut InterceptorContext<BeforeTransmit>,
            _cfg: &mut ConfigBag,
        ) -> Result<(), aws_smithy_runtime_api::client::interceptors::BoxError> {
            let request = context.request_mut();
            let uri = format!("{}{}", base_url(), request.uri().path());
            *request.uri_mut() = uri.parse()?;

            Ok(())
        }
    }
    builder.push_interceptor(SharedInterceptor::new(UriModifierInterceptor));
}

let mut builder = Config::builder();
modify_request_uri(&mut builder);
let config = builder.build();
source

pub fn set_interceptors( &mut self, interceptors: impl IntoIterator<Item = SharedInterceptor>, ) -> &mut Self

Set SharedInterceptors for the builder.

source

pub fn time_source(self, time_source: impl TimeSource + 'static) -> Self

Sets the time source used for this service

source

pub fn set_time_source( &mut self, time_source: Option<SharedTimeSource>, ) -> &mut Self

Sets the time source used for this service

source

pub fn retry_classifier( self, retry_classifier: impl ClassifyRetry + 'static, ) -> Self

Add type implementing ClassifyRetry that will be used by the RetryStrategy to determine what responses should be retried.

A retry classifier configured by this method will run according to its priority.

§Examples
use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
use aws_smithy_runtime_api::client::orchestrator::OrchestratorError;
use aws_smithy_runtime_api::client::retries::classifiers::{
    ClassifyRetry, RetryAction, RetryClassifierPriority,
};
use aws_smithy_types::error::metadata::ProvideErrorMetadata;
use aws_smithy_types::retry::ErrorKind;
use std::error::Error as StdError;
use std::marker::PhantomData;
use aws_sdk_sts::config::Config;

const RETRYABLE_ERROR_CODES: &[&str] = [
    // List error codes to be retried here...
];

// When classifying at an operation's error type, classifiers require a generic parameter.
// When classifying the HTTP response alone, no generic is needed.
#[derive(Debug, Default)]
pub struct ErrorCodeClassifier<E> {
    _inner: PhantomData<E>,
}

impl<E> ExampleErrorCodeClassifier<E> {
    pub fn new() -> Self {
        Self {
            _inner: PhantomData,
        }
    }
}

impl<E> ClassifyRetry for ExampleErrorCodeClassifier<E>
where
    // Adding a trait bound for ProvideErrorMetadata allows us to inspect the error code.
    E: StdError + ProvideErrorMetadata + Send + Sync + 'static,
{
    fn classify_retry(&self, ctx: &InterceptorContext) -> RetryAction {
        // Check for a result
        let output_or_error = ctx.output_or_error();
        // Check for an error
        let error = match output_or_error {
            Some(Ok(_)) | None => return RetryAction::NoActionIndicated,
              Some(Err(err)) => err,
        };

        // Downcast the generic error and extract the code
        let error_code = OrchestratorError::as_operation_error(error)
            .and_then(|err| err.downcast_ref::<E>())
            .and_then(|err| err.code());

        // If this error's code is in our list, return an action that tells the RetryStrategy to retry this request.
        if let Some(error_code) = error_code {
            if RETRYABLE_ERROR_CODES.contains(&error_code) {
                return RetryAction::transient_error();
            }
        }

        // Otherwise, return that no action is indicated i.e. that this classifier doesn't require a retry.
        // Another classifier may still classify this response as retryable.
        RetryAction::NoActionIndicated
    }

    fn name(&self) -> &'static str { "Example Error Code Classifier" }
}

let config = Config::builder()
    .retry_classifier(ExampleErrorCodeClassifier::<SomeOperationError>::new())
    .build();
source

pub fn push_retry_classifier( &mut self, retry_classifier: SharedRetryClassifier, ) -> &mut Self

Add a SharedRetryClassifier that will be used by the RetryStrategy to determine what responses should be retried.

A retry classifier configured by this method will run according to its priority.

§Examples
use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
use aws_smithy_runtime_api::client::orchestrator::OrchestratorError;
use aws_smithy_runtime_api::client::retries::classifiers::{
    ClassifyRetry, RetryAction, RetryClassifierPriority,
};
use aws_smithy_types::error::metadata::ProvideErrorMetadata;
use aws_smithy_types::retry::ErrorKind;
use std::error::Error as StdError;
use std::marker::PhantomData;
use aws_sdk_sts::config::{Builder, Config};

const RETRYABLE_ERROR_CODES: &[&str] = [
    // List error codes to be retried here...
];
fn set_example_error_code_classifier(builder: &mut Builder) {
    // When classifying at an operation's error type, classifiers require a generic parameter.
    // When classifying the HTTP response alone, no generic is needed.
    #[derive(Debug, Default)]
    pub struct ExampleErrorCodeClassifier<E> {
        _inner: PhantomData<E>,
    }

    impl<E> ExampleErrorCodeClassifier<E> {
        pub fn new() -> Self {
            Self {
                _inner: PhantomData,
            }
        }
    }

    impl<E> ClassifyRetry for ExampleErrorCodeClassifier<E>
    where
        // Adding a trait bound for ProvideErrorMetadata allows us to inspect the error code.
        E: StdError + ProvideErrorMetadata + Send + Sync + 'static,
    {
        fn classify_retry(&self, ctx: &InterceptorContext) -> RetryAction {
            // Check for a result
            let output_or_error = ctx.output_or_error();
            // Check for an error
            let error = match output_or_error {
                Some(Ok(_)) | None => return RetryAction::NoActionIndicated,
                  Some(Err(err)) => err,
            };

            // Downcast the generic error and extract the code
            let error_code = OrchestratorError::as_operation_error(error)
                .and_then(|err| err.downcast_ref::<E>())
                .and_then(|err| err.code());

            // If this error's code is in our list, return an action that tells the RetryStrategy to retry this request.
            if let Some(error_code) = error_code {
                if RETRYABLE_ERROR_CODES.contains(&error_code) {
                    return RetryAction::transient_error();
                }
            }

            // Otherwise, return that no action is indicated i.e. that this classifier doesn't require a retry.
            // Another classifier may still classify this response as retryable.
            RetryAction::NoActionIndicated
        }

        fn name(&self) -> &'static str { "Example Error Code Classifier" }
    }

    builder.push_retry_classifier(ExampleErrorCodeClassifier::<SomeOperationError>::new())
}

let mut builder = Config::builder();
set_example_error_code_classifier(&mut builder);
let config = builder.build();
source

pub fn set_retry_classifiers( &mut self, retry_classifiers: impl IntoIterator<Item = SharedRetryClassifier>, ) -> &mut Self

Set SharedRetryClassifiers for the builder, replacing any that were previously set.

source

pub fn app_name(self, app_name: AppName) -> Self

Sets the name of the app that is using the client.

This optional name is used to identify the application in the user agent that gets sent along with requests.

source

pub fn set_app_name(&mut self, app_name: Option<AppName>) -> &mut Self

Sets the name of the app that is using the client.

This optional name is used to identify the application in the user agent that gets sent along with requests.

source

pub fn invocation_id_generator( self, gen: impl InvocationIdGenerator + 'static, ) -> Self

Overrides the default invocation ID generator.

The invocation ID generator generates ID values for the amz-sdk-invocation-id header. By default, this will be a random UUID. Overriding it may be useful in tests that examine the HTTP request and need to be deterministic.

source

pub fn set_invocation_id_generator( &mut self, gen: Option<SharedInvocationIdGenerator>, ) -> &mut Self

Overrides the default invocation ID generator.

The invocation ID generator generates ID values for the amz-sdk-invocation-id header. By default, this will be a random UUID. Overriding it may be useful in tests that examine the HTTP request and need to be deterministic.

source

pub fn endpoint_url(self, endpoint_url: impl Into<String>) -> Self

Sets the endpoint URL used to communicate with this service Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix will be prefixed onto this URL. To fully override the endpoint resolver, use Builder::endpoint_resolver.

source

pub fn set_endpoint_url(&mut self, endpoint_url: Option<String>) -> &mut Self

Sets the endpoint URL used to communicate with this service Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix will be prefixed onto this URL. To fully override the endpoint resolver, use Builder::endpoint_resolver.

source

pub fn use_dual_stack(self, use_dual_stack: impl Into<bool>) -> Self

When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.

source

pub fn set_use_dual_stack(&mut self, use_dual_stack: Option<bool>) -> &mut Self

When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.

source

pub fn use_fips(self, use_fips: impl Into<bool>) -> Self

When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.

source

pub fn set_use_fips(&mut self, use_fips: Option<bool>) -> &mut Self

When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.

source

pub fn region(self, region: impl Into<Option<Region>>) -> Self

Sets the AWS region to use when making requests.

§Examples
use aws_types::region::Region;
use aws_sdk_sts::config::{Builder, Config};

let config = aws_sdk_sts::Config::builder()
    .region(Region::new("us-east-1"))
    .build();
source

pub fn set_region(&mut self, region: Option<Region>) -> &mut Self

Sets the AWS region to use when making requests.

source

pub fn credentials_provider( self, credentials_provider: impl ProvideCredentials + 'static, ) -> Self

Sets the credentials provider for this service

source

pub fn set_credentials_provider( &mut self, credentials_provider: Option<SharedCredentialsProvider>, ) -> &mut Self

Sets the credentials provider for this service

source

pub fn behavior_version(self, behavior_version: BehaviorVersion) -> Self

Sets the behavior major version.

Over time, new best-practice behaviors are introduced. However, these behaviors might not be backwards compatible. For example, a change which introduces new default timeouts or a new retry-mode for all operations might be the ideal behavior but could break existing applications.

§Examples

Set the behavior major version to latest. This is equivalent to enabling the behavior-version-latest cargo feature.

use aws_sdk_sts::config::BehaviorVersion;

let config = aws_sdk_sts::Config::builder()
    .behavior_version(BehaviorVersion::latest())
    // ...
    .build();
let client = aws_sdk_sts::Client::from_conf(config);

Customizing behavior major version:

use aws_sdk_sts::config::BehaviorVersion;

let config = aws_sdk_sts::Config::builder()
    .behavior_version(BehaviorVersion::v2023_11_09())
    // ...
    .build();
let client = aws_sdk_sts::Client::from_conf(config);
source

pub fn set_behavior_version( &mut self, behavior_version: Option<BehaviorVersion>, ) -> &mut Self

Sets the behavior major version.

Over time, new best-practice behaviors are introduced. However, these behaviors might not be backwards compatible. For example, a change which introduces new default timeouts or a new retry-mode for all operations might be the ideal behavior but could break existing applications.

§Examples

Set the behavior major version to latest. This is equivalent to enabling the behavior-version-latest cargo feature.

use aws_sdk_sts::config::BehaviorVersion;

let config = aws_sdk_sts::Config::builder()
    .behavior_version(BehaviorVersion::latest())
    // ...
    .build();
let client = aws_sdk_sts::Client::from_conf(config);

Customizing behavior major version:

use aws_sdk_sts::config::BehaviorVersion;

let config = aws_sdk_sts::Config::builder()
    .behavior_version(BehaviorVersion::v2023_11_09())
    // ...
    .build();
let client = aws_sdk_sts::Client::from_conf(config);
source

pub fn behavior_version_latest(self) -> Self

Convenience method to set the latest behavior major version

This is equivalent to enabling the behavior-version-latest Cargo feature

source

pub fn apply_test_defaults(&mut self) -> &mut Self

Available on crate feature test-util only.

Apply test defaults to the builder

source

pub fn with_test_defaults(self) -> Self

Available on crate feature test-util only.

Apply test defaults to the builder

source

pub fn build(self) -> Config

Builds a Config.

Trait Implementations§

source§

impl Clone for Builder

source§

fn clone(&self) -> Builder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Builder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Builder

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<&SdkConfig> for Builder

source§

fn from(input: &SdkConfig) -> Self

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
§

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

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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