Struct tide_disco::app::Module

source ·
pub struct Module<'a, State, Error, ModuleError, ModuleVersion>
where State: Send + Sync + 'static, Error: Error + From<ModuleError> + 'static, ModuleError: Send + Sync + 'static, ModuleVersion: StaticVersionType + 'static,
{ /* private fields */ }
Expand description

RAII guard to ensure a module is registered after it is configured.

This type allows the owner to configure an Api module via the Deref and DerefMut traits. Once the API is configured, this object can be dropped, which will automatically register the module with the App.

§Panics

Note that if anything goes wrong during module registration (for example, there is already an incompatible module registered with the same name), the drop implementation may panic. To handle errors without panicking, call register explicitly.

Implementations§

source§

impl<'a, State, Error, ModuleError, ModuleVersion> Module<'a, State, Error, ModuleError, ModuleVersion>
where State: Send + Sync + 'static, Error: Error + From<ModuleError> + 'static, ModuleError: Send + Sync + 'static, ModuleVersion: StaticVersionType + 'static,

source

pub fn register(self) -> Result<(), AppError>

Register this module with the linked app.

Methods from Deref<Target = Api<State, ModuleError, ModuleVersion>>§

source

pub fn with_version(&mut self, version: Version) -> &mut Self

Set the API version.

The version information will automatically be included in responses to GET /version. This version can also be used to serve multiple major versions of the same API simultaneously, under a version prefix. For more information, see App::register_module.

This is the version of the application or sub-application which this instance of Api represents. The versioning corresponds to the API specification passed to new, and may be different from the version of the Rust crate implementing the route handlers for the API.

source

pub fn with_public(&mut self, dir: PathBuf) -> &mut Self

Serve the contents of dir at the URL /public/{{NAME}}.

source

pub fn at<F, T>( &mut self, name: &str, handler: F, ) -> Result<&mut Self, ApiError>
where F: 'static + Send + Sync + Fn(RequestParams, &State) -> BoxFuture<'_, Result<T, Error>>, T: Serialize, State: 'static + Send + Sync, VER: 'static + Send + Sync,

Register a handler for a route.

When the server receives a request whose URL matches the pattern of the route name, handler will be invoked with the parameters of the request and a reference to the current state, and the result will be serialized into a response.

§Examples

A simple getter route for a state object.

api.toml

[route.getstate]
PATH = ["/getstate"]
DOC = "Gets the current state."
use futures::FutureExt;

type State = u64;
type StaticVer01 = StaticVersion<0, 1>;

api.at("getstate", |req, state| async { Ok(*state) }.boxed());

A counter endpoint which increments a mutable state. Notice how we use METHOD = "POST" to ensure that the HTTP method for this route is compatible with mutable access.

api.toml

[route.increment]
PATH = ["/increment"]
METHOD = "POST"
DOC = "Increment the current state and return the new value."
use async_std::sync::Mutex;
use futures::FutureExt;

type State = Mutex<u64>;
type StaticVer01 = StaticVersion<0, 1>;

api.at("increment", |req, state| async {
    let mut guard = state.lock().await;
    *guard += 1;
    Ok(*guard)
}.boxed());
§Warnings

The route will use the HTTP method specified in the TOML specification for the named route (or GET if the method is not specified). Some HTTP methods imply constraints on mutability. For example, GET routes must be “pure”, and not mutate any server state. Violating this constraint may lead to confusing and unpredictable behavior. If the State type has interior mutability (for instance, RwLock) it is up to the handler not to use the interior mutability if the HTTP method suggests it shouldn’t.

If you know the HTTP method when you are registering the route, we recommend you use the safer versions of this function, which enforce the appropriate mutability constraints. For example,

§Errors

If the route name does not exist in the API specification, or if the route already has a handler registered, an error is returned. Note that all routes are initialized with a default handler that echoes parameters and shows documentation, but this default handler can replaced by this function without raising ApiError::HandlerAlreadyRegistered.

If the route name exists, but it is not an HTTP route (for example, METHOD = "SOCKET" was used when defining the route in the API specification), ApiError::IncorrectMethod is returned.

§Limitations

Like many function parameters in tide_disco, the handler function is required to return a [BoxFuture].

source

pub fn get<F, T>( &mut self, name: &str, handler: F, ) -> Result<&mut Self, ApiError>
where F: 'static + Send + Sync + Fn(RequestParams, &<State as ReadState>::State) -> BoxFuture<'_, Result<T, Error>>, T: Serialize, State: 'static + Send + Sync + ReadState, VER: 'static + Send + Sync,

Register a handler for a GET route.

When the server receives a GET request whose URL matches the pattern of the route name, handler will be invoked with the parameters of the request and immutable access to the current state, and the result will be serialized into a response.

The ReadState trait is used to acquire immutable access to the state, so the state reference passed to handler is actually <State as ReadState>::State. For example, if State is RwLock<T>, the lock will automatically be acquired for reading, and the handler will be passed a &T.

§Examples

A simple getter route for a state object.

api.toml

[route.getstate]
PATH = ["/getstate"]
DOC = "Gets the current state."
use async_std::sync::RwLock;
use futures::FutureExt;

type State = RwLock<u64>;
type StaticVer01 = StaticVersion<0, 1>;

api.get("getstate", |req, state| async { Ok(*state) }.boxed());
§Errors

If the route name does not exist in the API specification, or if the route already has a handler registered, an error is returned. Note that all routes are initialized with a default handler that echoes parameters and shows documentation, but this default handler can replaced by this function without raising ApiError::HandlerAlreadyRegistered.

If the route name exists, but the method is not GET (that is, METHOD = "M" was used in the route definition in api.toml, with M other than GET) the error IncorrectMethod is returned.

§Limitations

Like many function parameters in tide_disco, the handler function is required to return a [BoxFuture].

source

pub fn post<F, T>( &mut self, name: &str, handler: F, ) -> Result<&mut Self, ApiError>
where F: 'static + Send + Sync + Fn(RequestParams, &mut <State as ReadState>::State) -> BoxFuture<'_, Result<T, Error>>, T: Serialize, State: 'static + Send + Sync + WriteState, VER: 'static + Send + Sync,

Register a handler for a POST route.

When the server receives a POST request whose URL matches the pattern of the route name, handler will be invoked with the parameters of the request and exclusive, mutable access to the current state, and the result will be serialized into a response.

The WriteState trait is used to acquire mutable access to the state, so the state reference passed to handler is actually <State as ReadState>::State. For example, if State is RwLock<T>, the lock will automatically be acquired for writing, and the handler will be passed a &mut T.

§Examples

A counter endpoint which increments the state and returns the new state.

api.toml

[route.increment]
PATH = ["/increment"]
METHOD = "POST"
DOC = "Increment the current state and return the new value."
use async_std::sync::RwLock;
use futures::FutureExt;

type State = RwLock<u64>;
type StaticVer01 = StaticVersion<0, 1>;

api.post("increment", |req, state| async {
    *state += 1;
    Ok(*state)
}.boxed());
§Errors

If the route name does not exist in the API specification, or if the route already has a handler registered, an error is returned. Note that all routes are initialized with a default handler that echoes parameters and shows documentation, but this default handler can replaced by this function without raising ApiError::HandlerAlreadyRegistered.

If the route name exists, but the method is not POST (that is, METHOD = "M" was used in the route definition in api.toml, with M other than POST) the error IncorrectMethod is returned.

§Limitations

Like many function parameters in tide_disco, the handler function is required to return a [BoxFuture].

source

pub fn put<F, T>( &mut self, name: &str, handler: F, ) -> Result<&mut Self, ApiError>
where F: 'static + Send + Sync + Fn(RequestParams, &mut <State as ReadState>::State) -> BoxFuture<'_, Result<T, Error>>, T: Serialize, State: 'static + Send + Sync + WriteState, VER: 'static + Send + Sync,

Register a handler for a PUT route.

When the server receives a PUT request whose URL matches the pattern of the route name, handler will be invoked with the parameters of the request and exclusive, mutable access to the current state, and the result will be serialized into a response.

The WriteState trait is used to acquire mutable access to the state, so the state reference passed to handler is actually <State as ReadState>::State. For example, if State is RwLock<T>, the lock will automatically be acquired for writing, and the handler will be passed a &mut T.

§Examples

An endpoint which replaces the current state with a new value.

api.toml

[route.replace]
PATH = ["/replace/:new_state"]
METHOD = "PUT"
":new_state" = "Integer"
DOC = "Set the state to `:new_state`."
use async_std::sync::RwLock;
use futures::FutureExt;

type State = RwLock<u64>;
type StaticVer01 = StaticVersion<0, 1>;

api.post("replace", |req, state| async move {
    *state = req.integer_param("new_state")?;
    Ok(())
}.boxed());
§Errors

If the route name does not exist in the API specification, or if the route already has a handler registered, an error is returned. Note that all routes are initialized with a default handler that echoes parameters and shows documentation, but this default handler can replaced by this function without raising ApiError::HandlerAlreadyRegistered.

If the route name exists, but the method is not PUT (that is, METHOD = "M" was used in the route definition in api.toml, with M other than PUT) the error IncorrectMethod is returned.

§Limitations

Like many function parameters in tide_disco, the handler function is required to return a [BoxFuture].

source

pub fn delete<F, T>( &mut self, name: &str, handler: F, ) -> Result<&mut Self, ApiError>
where F: 'static + Send + Sync + Fn(RequestParams, &mut <State as ReadState>::State) -> BoxFuture<'_, Result<T, Error>>, T: Serialize, State: 'static + Send + Sync + WriteState, VER: 'static + Send + Sync,

Register a handler for a DELETE route.

When the server receives a DELETE request whose URL matches the pattern of the route name, handler will be invoked with the parameters of the request and exclusive, mutable access to the current state, and the result will be serialized into a response.

The WriteState trait is used to acquire mutable access to the state, so the state reference passed to handler is actually <State as ReadState>::State. For example, if State is RwLock<T>, the lock will automatically be acquired for writing, and the handler will be passed a &mut T.

§Examples

An endpoint which clears the current state.

api.toml

[route.state]
PATH = ["/state"]
METHOD = "DELETE"
DOC = "Clear the state."
use async_std::sync::RwLock;
use futures::FutureExt;

type State = RwLock<Option<u64>>;
type StaticVer01 = StaticVersion<0, 1>;

api.delete("state", |req, state| async {
    *state = None;
    Ok(())
}.boxed());
§Errors

If the route name does not exist in the API specification, or if the route already has a handler registered, an error is returned. Note that all routes are initialized with a default handler that echoes parameters and shows documentation, but this default handler can replaced by this function without raising ApiError::HandlerAlreadyRegistered.

If the route name exists, but the method is not DELETE (that is, METHOD = "M" was used in the route definition in api.toml, with M other than DELETE) the error IncorrectMethod is returned.

§Limitations

Like many function parameters in tide_disco, the handler function is required to return a [BoxFuture].

source

pub fn socket<F, ToClient, FromClient>( &mut self, name: &str, handler: F, ) -> Result<&mut Self, ApiError>
where F: 'static + Send + Sync + Fn(RequestParams, Connection<ToClient, FromClient, Error, VER>, &State) -> BoxFuture<'_, Result<(), Error>>, ToClient: 'static + Serialize + ?Sized, FromClient: 'static + DeserializeOwned, State: 'static + Send + Sync, Error: 'static + Send + Display,

Register a handler for a SOCKET route.

When the server receives any request whose URL matches the pattern for this route and which includes the WebSockets upgrade headers, the server will negotiate a protocol upgrade with the client, establishing a WebSockets connection, and then invoke handler. handler will be given the parameters of the request which initiated the connection and a reference to the application state, as well as a Connection object which it can then use for asynchronous, bi-directional communication with the client.

The server side of the connection will remain open as long as the future returned by handler is remains unresolved. The handler can terminate the connection by returning. If it returns an error, the error message will be included in the CloseFrame sent to the client when tearing down the connection.

§Examples

A socket endpoint which receives amounts from the client and returns a running sum.

api.toml

[route.sum]
PATH = ["/sum"]
METHOD = "SOCKET"
DOC = "Stream a running sum."
use futures::{FutureExt, SinkExt, StreamExt};
use tide_disco::{error::ServerError, socket::Connection, Api};

api.socket("sum", |_req, mut conn: Connection<i32, i32, ServerError, StaticVersion<0, 1>>, _state| async move {
    let mut sum = 0;
    while let Some(amount) = conn.next().await {
        sum += amount?;
        conn.send(&sum).await?;
    }
    Ok(())
}.boxed());

In some cases, it may be desirable to handle messages to and from the client in separate tasks. There are two ways of doing this:

§Split the connection into separate stream and sink
use async_std::task::spawn;
use futures::{future::{join, FutureExt}, sink::SinkExt, stream::StreamExt};
use tide_disco::{error::ServerError, socket::Connection, Api};

api.socket("endpoint", |_req, mut conn: Connection<i32, i32, ServerError, StaticVersion<0, 1>>, _state| async move {
    let (mut sink, mut stream) = conn.split();
    let recv = spawn(async move {
        while let Some(Ok(msg)) = stream.next().await {
            // Handle message from client.
        }
    });
    let send = spawn(async move {
        loop {
            let msg = // get message to send to client
            sink.send(msg).await;
        }
    });

    join(send, recv).await;
    Ok(())
}.boxed());

This approach requires messages to be sent to the client by value, consuming the message. This is because, if we were to use the Sync<&ToClient> implementation for Connection, the lifetime for &ToClient would be fixed after split is called, since the lifetime appears in the return type, SplitSink<Connection<...>, &ToClient>. Thus, this lifetime outlives any scoped local variables created after the split call, such as msg in the loop.

If we want to use the message after sending it to the client, we would have to clone it, which may be inefficient or impossible. Thus, there is another approach:

§Clone the connection
use async_std::task::spawn;
use futures::{future::{join, FutureExt}, sink::SinkExt, stream::StreamExt};
use tide_disco::{error::ServerError, socket::Connection, Api};

api.socket("endpoint", |_req, mut conn: Connection<i32, i32, ServerError, StaticVersion<0, 1>>, _state| async move {
    let recv = {
        let mut conn = conn.clone();
        spawn(async move {
            while let Some(Ok(msg)) = conn.next().await {
                // Handle message from client.
            }
        })
    };
    let send = spawn(async move {
        loop {
            let msg = // get message to send to client
            conn.send(&msg).await;
            // msg is still live at this point.
            drop(msg);
        }
    });

    join(send, recv).await;
    Ok(())
}.boxed());

Depending on the exact situation, this method may end up being more verbose than the previous example. But it allows us to retain the higher-ranked trait bound conn: for<'a> Sink<&'a ToClient> instead of fixing the lifetime, which can prevent an unnecessary clone in certain situations.

§Errors

If the route name does not exist in the API specification, or if the route already has a handler registered, an error is returned. Note that all routes are initialized with a default handler that echoes parameters and shows documentation, but this default handler can replaced by this function without raising ApiError::HandlerAlreadyRegistered.

If the route name exists, but the method is not SOCKET (that is, METHOD = "M" was used in the route definition in api.toml, with M other than SOCKET) the error IncorrectMethod is returned.

§Limitations

Like many function parameters in tide_disco, the handler function is required to return a [BoxFuture].

source

pub fn stream<F, Msg>( &mut self, name: &str, handler: F, ) -> Result<&mut Self, ApiError>
where F: 'static + Send + Sync + Fn(RequestParams, &State) -> BoxStream<'_, Result<Msg, Error>>, Msg: 'static + Serialize + Send + Sync, State: 'static + Send + Sync, Error: 'static + Send + Display, VER: 'static + Send + Sync,

Register a uni-directional handler for a SOCKET route.

This function is very similar to socket, but it permits the handler only to send messages to the client, not to receive messages back. As such, the handler does not take a Connection. Instead, it simply returns a stream of messages which are forwarded to the client as they are generated. If the stream ever yields an error, the error is propagated to the client and then the connection is closed.

This function can be simpler to use than socket in case the handler does not need to receive messages from the client.

source

pub fn metrics<F, T>( &mut self, name: &str, handler: F, ) -> Result<&mut Self, ApiError>
where F: 'static + Send + Sync + Fn(RequestParams, &State::State) -> BoxFuture<'_, Result<Cow<'_, T>, Error>>, T: 'static + Clone + Metrics, State: 'static + Send + Sync + ReadState, Error: 'static, VER: 'static + Send + Sync,

Register a handler for a METRICS route.

When the server receives any request whose URL matches the pattern for this route and whose headers indicate it is a request for metrics, the server will invoke this handler instead of the regular HTTP handler for the endpoint. Instead of returning a typed object to serialize, handler will return a Metrics object which will be serialized to plaintext using the Prometheus format.

A request is considered a request for metrics, for the purpose of dispatching to this handler, if the method is GET and the Accept header specifies text/plain as a better response type than application/json and application/octet-stream (other Tide Disco handlers respond to the content types application/json or application/octet-stream). As a special case, a request with no Accept header or Accept: * will return metrics when there is a metrics route matching the request URL, since metrics are given priority over other content types when multiple routes match the URL.

§Examples

A metrics endpoint which keeps track of how many times it has been called.

api.toml

[route.metrics]
PATH = ["/metrics"]
METHOD = "METRICS"
DOC = "Export Prometheus metrics."
use prometheus::{Counter, Registry};

struct State {
    counter: Counter,
    metrics: Registry,
}
type StaticVer01 = StaticVersion<0, 1>;

let mut api: Api<Mutex<State>, ServerError, StaticVer01>;
api.metrics("metrics", |_req, state| async move {
    state.counter.inc();
    Ok(Cow::Borrowed(&state.metrics))
}.boxed())?;
§Errors

If the route name does not exist in the API specification, or if the route already has a handler registered, an error is returned. Note that all routes are initialized with a default handler that echoes parameters and shows documentation, but this default handler can replaced by this function without raising ApiError::HandlerAlreadyRegistered.

If the route name exists, but the method is not METRICS (that is, METHOD = "M" was used in the route definition in api.toml, with M other than METRICS) the error IncorrectMethod is returned.

§Limitations

Like many function parameters in tide_disco, the handler function is required to return a [BoxFuture].

source

pub fn with_health_check<H>( &mut self, handler: impl 'static + Send + Sync + Fn(&State) -> BoxFuture<'_, H>, ) -> &mut Self
where State: 'static + Send + Sync, H: 'static + HealthCheck, VER: 'static + Send + Sync,

Set the health check handler for this API.

This overrides the existing handler. If health_check has not yet been called, the default handler is one which simply returns Health::default().

Trait Implementations§

source§

impl<'a, State, Error, ModuleError, ModuleVersion> Debug for Module<'a, State, Error, ModuleError, ModuleVersion>
where State: Send + Sync + 'static + Debug, Error: Error + From<ModuleError> + 'static + Debug, ModuleError: Send + Sync + 'static + Debug, ModuleVersion: StaticVersionType + 'static + Debug,

source§

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

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

impl<'a, State, Error, ModuleError, ModuleVersion> DerefMut for Module<'a, State, Error, ModuleError, ModuleVersion>
where State: Send + Sync + 'static, Error: Error + From<ModuleError> + 'static, ModuleError: Send + Sync + 'static, ModuleVersion: StaticVersionType + 'static,

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'a, State, Error, ModuleError, ModuleVersion> Drop for Module<'a, State, Error, ModuleError, ModuleVersion>
where State: Send + Sync + 'static, Error: Error + From<ModuleError> + 'static, ModuleError: Send + Sync + 'static, ModuleVersion: StaticVersionType + 'static,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, State, Error, ModuleError, ModuleVersion> Deref for Module<'a, State, Error, ModuleError, ModuleVersion>
where State: Send + Sync + 'static, Error: Error + From<ModuleError> + 'static, ModuleError: Send + Sync + 'static, ModuleVersion: StaticVersionType + 'static,

§

type Target = Api<State, ModuleError, ModuleVersion>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'a, State, Error, ModuleError, ModuleVersion> Freeze for Module<'a, State, Error, ModuleError, ModuleVersion>

§

impl<'a, State, Error, ModuleError, ModuleVersion> !RefUnwindSafe for Module<'a, State, Error, ModuleError, ModuleVersion>

§

impl<'a, State, Error, ModuleError, ModuleVersion> Send for Module<'a, State, Error, ModuleError, ModuleVersion>

§

impl<'a, State, Error, ModuleError, ModuleVersion> Sync for Module<'a, State, Error, ModuleError, ModuleVersion>

§

impl<'a, State, Error, ModuleError, ModuleVersion> Unpin for Module<'a, State, Error, ModuleError, ModuleVersion>
where ModuleVersion: Unpin,

§

impl<'a, State, Error, ModuleError, ModuleVersion> !UnwindSafe for Module<'a, State, Error, ModuleError, ModuleVersion>

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

§

impl<D> OwoColorize for D

§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
§

fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>

Change the foreground color to black
§

fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>

Change the background color to black
§

fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>

Change the foreground color to red
§

fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>

Change the background color to red
§

fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>

Change the foreground color to green
§

fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>

Change the background color to green
§

fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>

Change the foreground color to yellow
§

fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>

Change the background color to yellow
§

fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>

Change the foreground color to blue
§

fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>

Change the background color to blue
§

fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to magenta
§

fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the background color to magenta
§

fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to purple
§

fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the background color to purple
§

fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>

Change the foreground color to cyan
§

fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>

Change the background color to cyan
§

fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>

Change the foreground color to white
§

fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>

Change the background color to white
§

fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>

Change the foreground color to the terminal default
§

fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>

Change the background color to the terminal default
§

fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>

Change the foreground color to bright black
§

fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>

Change the background color to bright black
§

fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>

Change the foreground color to bright red
§

fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>

Change the background color to bright red
§

fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>

Change the foreground color to bright green
§

fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>

Change the background color to bright green
§

fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>

Change the foreground color to bright yellow
§

fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>

Change the background color to bright yellow
§

fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>

Change the foreground color to bright blue
§

fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>

Change the background color to bright blue
§

fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright magenta
§

fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the background color to bright magenta
§

fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright purple
§

fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the background color to bright purple
§

fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>

Change the foreground color to bright cyan
§

fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>

Change the background color to bright cyan
§

fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>

Change the foreground color to bright white
§

fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>

Change the background color to bright white
§

fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>

Make the text bold
§

fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>

Make the text dim
§

fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>

Make the text italicized
§

fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>

Make the text italicized
Make the text blink
Make the text blink (but fast!)
§

fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>

Swap the foreground and background colors
§

fn hidden<'a>(&'a self) -> HiddenDisplay<'a, Self>

Hide the text
§

fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>

Cross out the text
§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
source§

impl<T> Same for T

§

type Output = T

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