Skip to main content

OperationBuilder

Struct OperationBuilder 

Source
pub struct OperationBuilder<H = Missing, R = Missing, S = (), A = AuthNotSet, L = LicenseNotSet>
where H: HandlerSlot<S>, A: AuthState, L: LicenseState,
{ /* private fields */ }
Expand description

Type-safe operation builder with compile-time guarantees.

Generic parameters:

  • H: Handler state (Missing | Present)
  • R: Response state (Missing | Present)
  • S: Router state type (what you put into Router::with_state(S)).
  • A: Auth state (AuthNotSet | AuthSet)
  • L: License requirement state (LicenseNotSet | LicenseSet)

Implementations§

Source§

impl<S> OperationBuilder<Missing, Missing, S, AuthNotSet>

Source

pub fn new(method: Method, path: impl Into<String>) -> Self

Create a new operation builder with an HTTP method and path

Source

pub fn get(path: impl Into<String>) -> Self

Convenience constructor for GET requests

Source

pub fn post(path: impl Into<String>) -> Self

Convenience constructor for POST requests

Source

pub fn put(path: impl Into<String>) -> Self

Convenience constructor for PUT requests

Source

pub fn delete(path: impl Into<String>) -> Self

Convenience constructor for DELETE requests

Source

pub fn patch(path: impl Into<String>) -> Self

Convenience constructor for PATCH requests

Source§

impl<H, R, S, A, L> OperationBuilder<H, R, S, A, L>
where H: HandlerSlot<S>, A: AuthState, L: LicenseState,

Source

pub fn spec(&self) -> &OperationSpec

Inspect the spec (primarily for tests)

Source

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

Set the operation ID

Source

pub fn require_rate_limit( &mut self, rps: u32, burst: u32, in_flight: u32, ) -> &mut Self

Require per-route rate and concurrency limits. Stores metadata for the gateway to enforce.

Source

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

Set the operation summary

Source

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

Set the operation description

Source

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

Add a tag to the operation

Source

pub fn param(self, param: ParamSpec) -> Self

Add a parameter to the operation

Source

pub fn path_param( self, name: impl Into<String>, description: impl Into<String>, ) -> Self

Add a path parameter with type inference (defaults to string)

Source

pub fn query_param( self, name: impl Into<String>, required: bool, description: impl Into<String>, ) -> Self

Add a query parameter (defaults to string)

Source

pub fn query_param_typed( self, name: impl Into<String>, required: bool, description: impl Into<String>, param_type: impl Into<String>, ) -> Self

Add a typed query parameter with explicit OpenAPI type

Source

pub fn json_request_schema( self, schema_name: impl Into<String>, desc: impl Into<String>, ) -> Self

Attach a JSON request body by schema name that you’ve already registered. This variant sets a description (Some(desc)) and marks the body as required.

Source

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

Attach a JSON request body by schema name with no description (None). Marks the body as required.

Source

pub fn json_request<T>( self, registry: &dyn OpenApiRegistry, desc: impl Into<String>, ) -> Self
where T: ToSchema + PartialSchema + RequestApiDto + 'static,

Attach a JSON request body and auto-register its schema using utoipa. This variant sets a description (Some(desc)) and marks the body as required.

Source

pub fn json_request_no_desc<T>(self, registry: &dyn OpenApiRegistry) -> Self
where T: ToSchema + PartialSchema + RequestApiDto + 'static,

Attach a JSON request body (auto-register schema) with no description (None). Marks the body as required.

Source

pub fn request_optional(self) -> Self

Make the previously attached request body optional (if any).

Source

pub fn multipart_file_request( self, field_name: &str, description: Option<&str>, ) -> Self

Configure a multipart/form-data file upload request.

This is a convenience helper for file upload endpoints that:

  • Sets the request body content type to “multipart/form-data”
  • Sets a description for the request body
  • Configures an inline object schema with a binary file field
  • Restricts allowed Content-Type to only “multipart/form-data”

The file field will be documented in OpenAPI as a binary string with the given field name. This generates the correct OpenAPI schema for UI tools like Stoplight to display a file upload control.

§Arguments
  • field_name - Name of the multipart form field (e.g., “file”)
  • description - Optional description for the request body
§Example
let router = OperationBuilder::post("/files/v1/upload")
    .operation_id("upload_file")
    .summary("Upload a file")
    .multipart_file_request("file", Some("File to upload"))
    .public()
    .handler(upload_handler)
    .json_response(StatusCode::OK, "Upload successful")
    .register(router, &registry);
Source

pub fn octet_stream_request(self, description: Option<&str>) -> Self

Configure the request body as raw binary (application/octet-stream).

This is intended for endpoints that accept the entire request body as a file or arbitrary bytes, without multipart form encoding.

The OpenAPI schema will be:

requestBody:
  required: true
  content:
    application/octet-stream:
      schema:
        type: string
        format: binary

Tools like Stoplight will render this as a single file upload control for the entire body.

§Arguments
  • description - Optional description for the request body
§Example
let router = OperationBuilder::post("/files/v1/upload")
    .operation_id("upload_file")
    .summary("Upload a file")
    .octet_stream_request(Some("Raw file bytes to parse"))
    .public()
    .handler(upload_handler)
    .json_response(StatusCode::OK, "Upload successful")
    .register(router, &registry);
Source

pub fn allow_content_types(self, types: &[&'static str]) -> Self

Configure allowed request MIME types for this operation.

This attaches a whitelist of allowed Content-Type values (without parameters), which will be enforced by gateway middleware. If a request arrives with a Content-Type that is not in this list, gateway will return HTTP 415.

This is independent of the request body schema - it only configures gateway validation and does not affect OpenAPI request body specifications.

§Example
let router = OperationBuilder::post("/files/v1/upload")
    .operation_id("upload_file")
    .allow_content_types(&["multipart/form-data", "application/pdf"])
    .public()
    .handler(upload_handler)
    .json_response(StatusCode::OK, "Upload successful")
    .register(router, &registry);
Source§

impl<H, R, S> OperationBuilder<H, R, S, AuthSet, LicenseNotSet>
where H: HandlerSlot<S>,

License requirement setting — transitions LicenseNotSet -> LicenseSet

Source

pub fn require_license_features<F>( self, licenses: impl IntoIterator<Item = F>, ) -> OperationBuilder<H, R, S, AuthSet, LicenseSet>
where F: LicenseFeature,

Set (or explicitly clear) the license feature requirement for this operation.

This method is only available after the auth requirement has been decided (i.e. after calling authenticated()).

Mandatory for authenticated endpoints: operations configured with authenticated() must call require_license_features(...) before register(), because register() is only available once the license requirement state has transitioned to LicenseSet.

Not available for public endpoints: public routes cannot (and do not need to) call this method.

Pass an empty iterator (e.g. []) to explicitly declare that no license feature is required.

Source

pub fn no_license_required( self, ) -> OperationBuilder<H, R, S, AuthSet, LicenseSet>

Explicitly declare that this operation does not require any license.

Use this for system/infrastructure endpoints that need authentication but are not gated behind application-level license features.

This transitions from LicenseNotSet to LicenseSet without attaching any license requirement.

Source§

impl<H, R, S, L> OperationBuilder<H, R, S, AuthNotSet, L>
where H: HandlerSlot<S>, L: LicenseState,

Source

pub fn authenticated(self) -> OperationBuilder<H, R, S, AuthSet, L>

Mark this route as requiring authentication.

This is a binary marker — the route requires a valid bearer token. Scope enforcement (which scopes are needed) is configured at the gateway level, not per-route.

This method transitions from AuthNotSet to AuthSet state.

§Example
enum License {
    Base,
}

impl AsRef<str> for License {
    fn as_ref(&self) -> &str {
        match self {
            License::Base => "gts.x.core.lic.feat.v1~x.core.global.base.v1",
        }
    }
}

impl LicenseFeature for License {}

let router = OperationBuilder::get("/users-info/v1/users")
    .authenticated()
    .require_license_features::<License>([])
    .handler(list_users_handler)
    .json_response(axum::http::StatusCode::OK, "List of users")
    .register(router, api);
Source

pub fn public(self) -> OperationBuilder<H, R, S, AuthSet, LicenseSet>

Mark this route as public (no authentication required).

This explicitly opts out of the require_auth_by_default setting. This method transitions from AuthNotSet to AuthSet state.

§Example
let router = OperationBuilder::get("/users-info/v1/health")
    .public()
    .handler(health_check)
    .json_response(StatusCode::OK, "OK")
    .register(router, &registry);
Source§

impl<R, S, A, L> OperationBuilder<Missing, R, S, A, L>
where S: Clone + Send + Sync + 'static, A: AuthState, L: LicenseState,

Source

pub fn handler<F, T>(self, h: F) -> OperationBuilder<Present, R, S, A, L>
where F: Handler<T, S> + Clone + Send + 'static, T: 'static,

Set the handler for this operation (function handlers are recommended).

This transitions the builder from Missing to Present handler state.

Source

pub fn method_router( self, mr: MethodRouter<S>, ) -> OperationBuilder<Present, R, S, A, L>

Alternative path: provide a pre-composed MethodRouter<S> yourself (useful to attach per-route middleware/layers).

Source§

impl<H, S, A, L> OperationBuilder<H, Missing, S, A, L>
where H: HandlerSlot<S>, A: AuthState, L: LicenseState,

Source

pub fn response( self, resp: ResponseSpec, ) -> OperationBuilder<H, Present, S, A, L>

Add a raw response spec (transitions from Missing to Present).

Source

pub fn json_response( self, status: StatusCode, description: impl Into<String>, ) -> OperationBuilder<H, Present, S, A, L>

Add a JSON response (transitions from Missing to Present).

Source

pub fn json_response_with_schema<T>( self, registry: &dyn OpenApiRegistry, status: StatusCode, description: impl Into<String>, ) -> OperationBuilder<H, Present, S, A, L>
where T: ToSchema + PartialSchema + ResponseApiDto + 'static,

Add a JSON response with a registered schema (transitions from Missing to Present).

Source

pub fn text_response( self, status: StatusCode, description: impl Into<String>, content_type: &'static str, ) -> OperationBuilder<H, Present, S, A, L>

Add a text response with a custom content type (transitions from Missing to Present).

§Arguments
  • status - HTTP status code
  • description - Description of the response
  • content_type - Pure media type without parameters (e.g., "text/plain", "text/markdown")
§Important

The content_type must be a pure media type without parameters like ; charset=utf-8. OpenAPI media type keys cannot include parameters. Use "text/markdown" instead of "text/markdown; charset=utf-8". Actual HTTP response headers in handlers should still include the charset parameter.

Source

pub fn html_response( self, status: StatusCode, description: impl Into<String>, ) -> OperationBuilder<H, Present, S, A, L>

Add an HTML response (transitions from Missing to Present).

Source

pub fn problem_response( self, registry: &dyn OpenApiRegistry, status: StatusCode, description: impl Into<String>, ) -> OperationBuilder<H, Present, S, A, L>

Add an RFC 9457 application/problem+json response (transitions from Missing to Present).

Source

pub fn sse_json<T>( self, openapi: &dyn OpenApiRegistry, description: impl Into<String>, ) -> OperationBuilder<H, Present, S, A, L>
where T: ToSchema + PartialSchema + ResponseApiDto + 'static,

First response: SSE stream of JSON events (text/event-stream).

Source§

impl<H, S, A, L> OperationBuilder<H, Present, S, A, L>
where H: HandlerSlot<S>, A: AuthState, L: LicenseState,

Source

pub fn json_response( self, status: StatusCode, description: impl Into<String>, ) -> Self

Add a JSON response (additional).

Source

pub fn json_response_with_schema<T>( self, registry: &dyn OpenApiRegistry, status: StatusCode, description: impl Into<String>, ) -> Self
where T: ToSchema + PartialSchema + ResponseApiDto + 'static,

Add a JSON response with a registered schema (additional).

Source

pub fn text_response( self, status: StatusCode, description: impl Into<String>, content_type: &'static str, ) -> Self

Add a text response with a custom content type (additional).

§Arguments
  • status - HTTP status code
  • description - Description of the response
  • content_type - Pure media type without parameters (e.g., "text/plain", "text/markdown")
§Important

The content_type must be a pure media type without parameters like ; charset=utf-8. OpenAPI media type keys cannot include parameters. Use "text/markdown" instead of "text/markdown; charset=utf-8". Actual HTTP response headers in handlers should still include the charset parameter.

Source

pub fn html_response( self, status: StatusCode, description: impl Into<String>, ) -> Self

Add an HTML response (additional).

Source

pub fn problem_response( self, registry: &dyn OpenApiRegistry, status: StatusCode, description: impl Into<String>, ) -> Self

Add an additional RFC 9457 application/problem+json response.

Source

pub fn sse_json<T>( self, openapi: &dyn OpenApiRegistry, description: impl Into<String>, ) -> Self
where T: ToSchema + PartialSchema + ResponseApiDto + 'static,

Additional SSE response (if the operation already has a response).

Source

pub fn standard_errors(self, registry: &dyn OpenApiRegistry) -> Self

Add standard error responses (400, 401, 403, 404, 409, 422, 429, 500).

All responses reference the shared Problem schema (RFC 9457) for consistent error handling across your API. This is the recommended way to declare common error responses without repeating boilerplate.

§Example
let op = OperationBuilder::get("/user-info/v1/users")
    .public()
    .handler(list_users)
    .json_response(StatusCode::OK, "List of users")
    .standard_errors(&registry);

let router = op.register(router, &registry);

This adds the following error responses:

  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden
  • 404 Not Found
  • 409 Conflict
  • 422 Unprocessable Entity
  • 429 Too Many Requests
  • 500 Internal Server Error
Source

pub fn with_422_validation_error(self, registry: &dyn OpenApiRegistry) -> Self

Add 422 validation error response using ValidationError schema.

This method adds a specific 422 Unprocessable Entity response that uses the ValidationError schema instead of the generic Problem schema. Use this for endpoints that perform input validation and need structured error details.

§Example
#[modkit_macros::api_dto(request)]
struct CreateUserRequest {
    email: String,
}

let op = OperationBuilder::post("/users-info/v1/users")
    .public()
    .handler(create_user)
    .json_request::<CreateUserRequest>(&registry, "User data")
    .json_response(StatusCode::CREATED, "User created")
    .with_422_validation_error(&registry);

let router = op.register(router, &registry);
Source

pub fn error_400(self, registry: &dyn OpenApiRegistry) -> Self

Add a 400 Bad Request error response.

This is a convenience wrapper around problem_response.

Source

pub fn error_401(self, registry: &dyn OpenApiRegistry) -> Self

Add a 401 Unauthorized error response.

This is a convenience wrapper around problem_response.

Source

pub fn error_403(self, registry: &dyn OpenApiRegistry) -> Self

Add a 403 Forbidden error response.

This is a convenience wrapper around problem_response.

Source

pub fn error_404(self, registry: &dyn OpenApiRegistry) -> Self

Add a 404 Not Found error response.

This is a convenience wrapper around problem_response.

Source

pub fn error_409(self, registry: &dyn OpenApiRegistry) -> Self

Add a 409 Conflict error response.

This is a convenience wrapper around problem_response.

Source

pub fn error_415(self, registry: &dyn OpenApiRegistry) -> Self

Add a 415 Unsupported Media Type error response.

This is a convenience wrapper around problem_response.

Source

pub fn error_422(self, registry: &dyn OpenApiRegistry) -> Self

Add a 422 Unprocessable Entity error response.

This is a convenience wrapper around problem_response.

Source

pub fn error_429(self, registry: &dyn OpenApiRegistry) -> Self

Add a 429 Too Many Requests error response.

This is a convenience wrapper around problem_response.

Source

pub fn error_500(self, registry: &dyn OpenApiRegistry) -> Self

Add a 500 Internal Server Error response.

This is a convenience wrapper around problem_response.

Source§

impl<S> OperationBuilder<Present, Present, S, AuthSet, LicenseSet>
where S: Clone + Send + Sync + 'static,

Source

pub fn register( self, router: Router<S>, openapi: &dyn OpenApiRegistry, ) -> Router<S>

Register the operation with the router and OpenAPI registry.

This method is only available when:

  • Handler is present
  • Response is present
  • Auth requirement is set (either authenticated or public)

All conditions are enforced at compile time by the type system.

Trait Implementations§

Source§

impl<S, H, R, A, L> OperationBuilderODataExt<S, H, R> for OperationBuilder<H, R, S, A, L>
where H: HandlerSlot<S>, A: AuthState, L: LicenseState,

Source§

fn with_odata_filter<T>(self) -> Self
where T: FilterField,

Adds optional $filter query parameter to OpenAPI.
Source§

fn with_odata_select(self) -> Self

Adds optional $select query parameter to OpenAPI.
Source§

fn with_odata_orderby<T>(self) -> Self
where T: FilterField,

Adds optional $orderby query parameter to OpenAPI.

Auto Trait Implementations§

§

impl<H, R, S, A, L> Freeze for OperationBuilder<H, R, S, A, L>
where <H as HandlerSlot<S>>::Slot: Freeze,

§

impl<H, R, S, A, L> RefUnwindSafe for OperationBuilder<H, R, S, A, L>

§

impl<H, R, S, A, L> Send for OperationBuilder<H, R, S, A, L>
where <H as HandlerSlot<S>>::Slot: Send, H: Send, R: Send, A: Send, L: Send,

§

impl<H, R, S, A, L> Sync for OperationBuilder<H, R, S, A, L>
where <H as HandlerSlot<S>>::Slot: Sync, H: Sync, R: Sync, A: Sync, L: Sync,

§

impl<H, R, S, A, L> Unpin for OperationBuilder<H, R, S, A, L>
where <H as HandlerSlot<S>>::Slot: Unpin, H: Unpin, R: Unpin, A: Unpin, L: Unpin,

§

impl<H, R, S, A, L> UnsafeUnpin for OperationBuilder<H, R, S, A, L>
where <H as HandlerSlot<S>>::Slot: UnsafeUnpin,

§

impl<H, R, S, A, L> UnwindSafe for OperationBuilder<H, R, S, A, L>

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.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

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

Source§

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

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

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

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
Source§

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

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

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

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

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

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

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

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

§Example
println!("{}", value.rgb(r, g, b));
Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
Source§

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

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

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

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

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

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

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

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

§Example
println!("{}", value.on_rgb(r, g, b));
Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Enables the styling Attribute value.

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

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Enables the yansi Quirk value.

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

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

fn whenever(&self, value: Condition) -> Painted<&T>

Conditionally enable styling based on whether the Condition value applies. Replaces any previous condition.

See the crate level docs for more details.

§Example

Enable styling painted only when both stdout and stderr are TTYs:

use yansi::{Paint, Condition};

painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
Source§

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

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

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
Source§

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

Source§

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

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

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSecurityContext for T

Source§

fn security_ctx<'a>(&'a self, ctx: &'a SecurityContext) -> Secured<'a, T>

Binds a security context to this client, returning a Secured wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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