Skip to main content

Manager

Struct Manager 

Source
pub struct Manager<T> { /* private fields */ }
Expand description

Entry point for queries on a model.

Manager<T> wraps a freshly-constructed QuerySet<T> and exposes the same chainable surface. The user never constructs one directly; Post::objects() is the only door.

Implementations§

Source§

impl<T: Model> Manager<T>

Manager convenience shims so callers can write Post::objects().load_fixture(...) and dump_fixture(...) without importing the free functions.

Source

pub async fn load_fixture<P: AsRef<Path>>( &self, path: P, ) -> Result<usize, FixtureError>

Source

pub async fn dump_fixture<P: AsRef<Path>>( &self, path: P, ) -> Result<usize, FixtureError>

Source§

impl<T> Manager<T>

Source

pub fn atomic(self) -> Self

Wrap every write terminal that hangs off this Manager in a transaction. Equivalent to calling .atomic() on each QuerySet derived from it. Per-call .non_atomic() overrides.

Source

pub fn non_atomic(self) -> Self

Opt this Manager (and every QuerySet derived from it) out of the global App::builder().atomic_transactions(true) default.

Source§

impl<T: Model> Manager<T>

Delegating chainable + terminal surface on Manager<T>.

Lets users write Post::objects().filter(...).fetch().await without a separate .query() hop. Each method constructs the initial SelectStatement against T::TABLE with one column per T::FIELDS entry, wraps it in a fresh QuerySet<T>, and forwards.

Source

pub fn filter(&self, p: Predicate<T>) -> QuerySet<T>

See QuerySet::filter.

Source

pub fn exclude(&self, p: Predicate<T>) -> QuerySet<T>

See QuerySet::exclude.

Source

pub fn all(&self) -> QuerySet<T>

A bare QuerySet over every row — the Model::objects().all() form.

The entry point when you need a QuerySet terminal without a filter: a grouped aggregate over the whole table, an unfiltered aggregate, or just an explicit “all rows” for readability.

Source

pub async fn aggregate( &self, aggs: &[(&str, Aggregate)], ) -> Result<JsonValue, Error>

See QuerySet::aggregate — single-row aggregate over every row.

Forwards from the manager so Model::objects().aggregate(...) works without an intervening .filter(...) / .on(...).

Source

pub async fn annotate( &self, group_cols: &[&str], aggs: &[(&str, Aggregate)], ) -> Result<Vec<JsonValue>, Error>

See QuerySet::annotate — grouped aggregate (GROUP BY <group_cols>).

Forwards from the manager so the documented Model::objects().annotate(&["status"], &[("count", Aggregate::count())]) (a grouped count over "status") compiles directly, without a filter first.

Source

pub fn with_deleted(&self) -> QuerySet<T>

Feature #72 — see QuerySet::with_deleted.

Source

pub fn only_deleted(&self) -> QuerySet<T>

Feature #72 — see QuerySet::only_deleted.

Source

pub fn only(&self, cols: &[&str]) -> QuerySet<T>

Gap #111 — see QuerySet::only.

Source

pub fn hard_delete(&self) -> QuerySet<T>

Feature #72 — see QuerySet::hard_delete.

Source

pub fn into_subquery(&self, col_name: &str) -> Subquery

See QuerySet::into_subquery.

Source

pub fn order_by(&self, o: OrderExpr<T>) -> QuerySet<T>

See QuerySet::order_by.

Source

pub fn limit(&self, n: u64) -> QuerySet<T>

See QuerySet::limit.

Source

pub fn offset(&self, n: u64) -> QuerySet<T>

See QuerySet::offset.

Source

pub fn on(&self, pool: &SqlitePool) -> QuerySet<T>

See QuerySet::on.

Source

pub fn on_pg(&self, pool: &PgPool) -> QuerySet<T>

See QuerySet::on_pg.

Source

pub async fn fetch(&self) -> Result<Vec<T>, Error>
where T: for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow> + HydrateRelated,

See QuerySet::fetch.

Source

pub async fn first(&self) -> Result<Option<T>, Error>
where T: for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow> + HydrateRelated,

See QuerySet::first.

Source

pub async fn count(&self) -> Result<i64, Error>

See QuerySet::count.

See QuerySet::annotate_related — starts an annotated chain from the manager, like filter does.

Source

pub fn annotate_count(&self, relation: &str) -> QuerySet<T>

Source

pub fn annotate_count_where<C: Model>( &self, alias: &str, relation: &str, pred: Predicate<C>, ) -> QuerySet<T>

See QuerySet::annotate_count_where — starts a filtered annotated chain from the manager.

Source

pub async fn fetch_annotated( &self, ) -> Result<Vec<(T, Map<String, JsonValue>)>, Error>
where T: for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow>,

Source

pub async fn values(&self, columns: &[&str]) -> Result<Vec<JsonValue>, Error>

Source

pub async fn exists(&self) -> Result<bool, Error>
where T: for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow> + HydrateRelated,

See QuerySet::exists.

Source

pub async fn get(&self, p: Predicate<T>) -> Result<T, GetError>
where T: for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow> + HydrateRelated,

.get(predicate) — sugar for .filter(predicate).get().

The one-liner: User::objects().get(user::ID.eq(1)). See QuerySet::get for error-variant semantics.

Source

pub async fn fetch_pg(&self, pool: &PgPool) -> Result<Vec<T>, Error>
where T: for<'r> FromRow<'r, PgRow>,

Source

pub async fn first_pg(&self, pool: &PgPool) -> Result<Option<T>, Error>
where T: for<'r> FromRow<'r, PgRow>,

Source

pub async fn count_pg(&self, pool: &PgPool) -> Result<i64, Error>

Source

pub async fn exists_pg(&self, pool: &PgPool) -> Result<bool, Error>
where T: for<'r> FromRow<'r, PgRow>,

Source

pub async fn get_pg( &self, pool: &PgPool, p: Predicate<T>, ) -> Result<T, GetError>
where T: for<'r> FromRow<'r, PgRow>,

Postgres-only sugar for .filter(predicate).get_pg(pool).

Source

pub async fn create(&self, instance: T) -> Result<T, WriteError>
where T: Serialize + for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow> + HydrateRelated,

INSERT one row, return the row as it now exists in the database (with any autoincrement PK populated). Uses the ambient pool via Manager::queryset().resolve_pool.

Source

pub async fn bulk_create(&self, instances: Vec<T>) -> Result<u64, WriteError>
where T: Serialize,

INSERT many rows in a single statement. Returns the number of rows inserted. The full populated rows aren’t materialised — use a follow-up Model::objects().filter(...).fetch() if you need them.

Empty input is a no-op (returns Ok(0)) — the alternative (building an INSERT INTO t () VALUES () and failing at the DB) doesn’t help anyone.

Fires bulk_post_save:<table> once with { ids, created: true, actor } when at least one row was inserted. Per-row pre_save / post_save are NOT fired — use Self::save when per-row signal semantics are required.

Source

pub async fn get_or_create( &self, predicate: Predicate<T>, defaults: T, ) -> Result<(T, bool), WriteError>
where T: Serialize + for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow> + HydrateRelated,

The get_or_create terminal: fetch the first row matching predicate; if none exists, insert defaults and return it. Returns (row, created) so the caller can branch on whether the write happened. Two queries on the miss path (filter+first then create), one query on the hit path.

§Concurrency

Convergent under concurrent callers: if two callers both miss the SELECT and race to INSERT, the one that loses gets a UniqueViolation; that error is caught here and the existing row is re-fetched, so both callers return the same row with created = false for the loser. A UNIQUE constraint on the predicate columns is required for true at-most-one semantics — the constraint is what makes the convergence deterministic.

Source

pub async fn update_or_create( &self, predicate: Predicate<T>, defaults: T, ) -> Result<(T, bool), WriteError>
where T: Serialize + Clone + for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow> + HydrateRelated,

The update_or_create terminal: fetch the first row matching predicate; if found, update its non-PK columns with the defaults instance’s values and return the fresh row; otherwise insert defaults and return it. Returns (row, created) so the caller can branch on the path taken.

The defaults’ PK is intentionally ignored on the update path — the matched row keeps its original PK. On the insert path the defaults’ PK is honoured (autoincrement sentinel 0 → DB assigns; explicit value → DB uses it).

§Concurrency

Convergent under concurrent callers: if two callers both miss the SELECT and race to INSERT, the loser gets a UniqueViolation; that error is caught here and the existing row is re-fetched, then the update is applied to it. Both callers converge on the same row, with created = false for the loser. A UNIQUE constraint on the predicate columns is required for deterministic convergence.

Implementation: 2 queries on the hit path (first + UPDATE + re-fetch), 2 queries on the miss+create path (first + create), or 4 queries on the miss+race path (first + failed-INSERT + first

  • UPDATE + re-fetch).
Source

pub async fn upsert(&self, instance: T) -> Result<T, WriteError>
where T: Serialize + for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow>,

INSERT-or-UPDATE keyed on the primary key. The row’s PK column is the conflict target; on a hit, every non-PK column is overwritten with the supplied value. Returns the row as the DB stored it (post-upsert).

Both backends use INSERT ... ON CONFLICT(<pk>) DO UPDATE SET col = excluded.col, .... The SQLite and Postgres syntax happens to match exactly here so a single sea-query OnConflict builder covers both.

Source

pub async fn create_pg( &self, instance: T, pool: &PgPool, ) -> Result<T, WriteError>
where T: Serialize + for<'r> FromRow<'r, PgRow>,

create against an explicit Postgres pool. The Postgres counterpart of Self::create for models with Postgres-only field types (Array, Inet, MacAddr, FullText), whose FromRow impl exists only for PgRow.

Source

pub async fn bulk_update(&self, instances: Vec<T>) -> Result<u64, WriteError>
where T: Serialize,

Apply per-row differing values to a list of instances in one statement. Each instance carries its own PK and its own column values; the generated SQL uses one CASE pk WHEN ... THEN ... END per non-PK column, plus a WHERE pk IN (...) to scope the update.

A bulk_update(objs, fields) that updates every non-PK column rather than asking the caller to list them. Returns the number of rows affected.

Empty input is a no-op (returns 0). The pattern works on both SQLite and Postgres — the CASE expression is SQL-standard.

Limitations:

  • All instances must have a non-default PK (the caller has already loaded the rows). Default-PK instances are skipped.
  • Bulk-write signals are NOT fired by this path — it’s the Manager::bulk_create analogue for UPDATE, deliberately silent for speed.
Source

pub async fn raw(&self, sql: &str) -> Result<Vec<T>, Error>
where T: for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow>,

Run a hand-written SQL query and return typed Vec<T> rows.

The escape hatch for queries the QuerySet builder can’t (or shouldn’t) model — CTEs, vendor-specific functions, ad-hoc reporting. Delegates to sqlx::query_as against the ambient pool and dispatches on backend, so user code stays portable. The string is sent verbatim; no parameter binding (use Predicate / the typed query path for parameterised queries). Inject input only after manual sanitisation.

Skips the select_related / prefetch_related chain — those only apply to the typed QuerySet build path.

Source

pub async fn bulk_create_pg( &self, instances: Vec<T>, pool: &PgPool, ) -> Result<u64, WriteError>
where T: Serialize,

bulk_create against an explicit Postgres pool.

Source§

impl<T: Model> Manager<T>

Source

pub fn on_tx<'a>(&self, tx: &'a mut Transaction) -> QuerySetTx<'a, T>

Begin a new query on this manager attached to the given open transaction.

Sugar for T::objects().on_tx(tx) — lets callers skip the intermediate QuerySet construction when they want to go straight to a terminal:

umbral::db::transaction(|tx| async move {
    let post = Post::objects().on_tx(tx).create(new_post).await?;
    Ok::<_, MyError>(post)
}).await?;
Source

pub async fn create_in_tx( &self, instance: T, tx: &mut Transaction, ) -> Result<T, WriteError>
where T: Serialize + for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow> + HydrateRelated,

INSERT one row inside tx and return the populated row.

This is the primary Manager-level entry point for transactional writes. Equivalent to Post::objects().on_tx(tx).create(instance) but more ergonomic when you only need the one INSERT (no filter chain needed).

umbral::db::transaction(|tx| async move {
    let post = Post::objects().create_in_tx(new_post, tx).await?;
    Ok::<_, MyError>(post)
}).await?;
Source

pub async fn bulk_create_in_tx( &self, instances: Vec<T>, tx: &mut Transaction, ) -> Result<u64, WriteError>
where T: Serialize,

INSERT many rows inside tx.

Returns the number of rows inserted. Empty input is a no-op.

Source

pub async fn save(&self, instance: T) -> Result<T, SaveError>
where T: Serialize + for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow>,

Save one instance, firing pre_save + post_save signals.

Determines INSERT vs UPDATE by checking whether the primary key is the autoincrement sentinel (0 for integers, nil UUID, empty string). If it is, an INSERT is performed (created = true); otherwise an UPDATE ... WHERE pk = <value> is run (created = false).

Returns the row as it exists in the database after the write (populated PK for inserts, same row for updates).

§Signal contract
  • pre_save:<table> fires before the database write with { "instance": ..., "created": bool, "actor": ... }.
  • post_save:<table> fires after the database write with the DB-read-back row and the same envelope keys.

The "actor" value is set by the nearest enclosing crate::signals::with_actor scope; Value::Null when no scope is active.

§Bulk paths fire bulk signals, not per-row signals

Manager::create, Manager::bulk_create, and QuerySet::update_values / QuerySet::delete do NOT fire per-row post_save / post_delete. They fire bulk_post_save:<table> / bulk_post_delete:<table> once per statement with the affected PKs in the payload. Use save / delete_instance when per-row signal semantics are needed.

Source

pub async fn delete_instance(&self, instance: &T) -> Result<u64, SaveError>
where T: Serialize,

Delete one instance by primary key, firing pre_delete + post_delete signals.

Issues DELETE FROM <table> WHERE <pk> = <value>. Returns the number of rows affected (0 if the row was already gone, 1 otherwise).

§Signal contract
  • pre_delete:<table> fires before the DELETE with { "instance": ..., "actor": ... }.
  • post_delete:<table> fires after the DELETE with the same payload shape.

The "actor" value is set by the nearest enclosing crate::signals::with_actor scope; Value::Null when no scope is active. The instance value passed to both signals is the value supplied by the caller — not a DB read-back. If you need the freshest DB state before deletion, fetch it first with .get(...) then pass to this method.

§Bulk paths fire bulk signals

QuerySet::delete() (the filter-chain DELETE) fires bulk_post_delete:<table> with the list of affected PKs, not per-row pre_delete / post_delete. Use delete_instance for per-row signal semantics.

Trait Implementations§

Source§

impl<T> Default for Manager<T>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for Manager<T>

§

impl<T> RefUnwindSafe for Manager<T>
where T: RefUnwindSafe,

§

impl<T> Send for Manager<T>
where T: Send,

§

impl<T> Sync for Manager<T>
where T: Sync,

§

impl<T> Unpin for Manager<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Manager<T>

§

impl<T> UnwindSafe for Manager<T>
where T: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

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

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

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

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Enables the styling Attribute value.

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

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Enables the yansi Quirk value.

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

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
Source§

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

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

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

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

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

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

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

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

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

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

👎Deprecated since 1.0.1:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

See the crate level docs for more details.

§Example

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

use yansi::{Paint, Condition};

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

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

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

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

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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