CodeBuilder

Struct CodeBuilder 

Source
pub struct CodeBuilder<'a> {
    pub state: &'a mut CodeGenState,
    pub builder: &'a mut InstructionBuilder<'a>,
    pub variable_registers: SeqMap<usize, TypedRegister>,
    pub temp_registers: HwmTempRegisterPool,
    pub frame_allocator: StackFrameAllocator,
    pub debug_line_tracker: KeepTrackOfSourceLine,
    pub source_map_lookup: &'a SourceMapWrapper<'a>,
    pub options: CodeBuilderOptions,
    pub errors: Vec<Error>,
}

Fields§

§state: &'a mut CodeGenState§builder: &'a mut InstructionBuilder<'a>§variable_registers: SeqMap<usize, TypedRegister>§temp_registers: HwmTempRegisterPool§frame_allocator: StackFrameAllocator§debug_line_tracker: KeepTrackOfSourceLine§source_map_lookup: &'a SourceMapWrapper<'a>§options: CodeBuilderOptions§errors: Vec<Error>

Implementations§

Source§

impl CodeBuilder<'_>

Source

pub fn emit_block_copy_with_size_from_location( &mut self, destination_location: &MemoryLocation, source_location: &MemoryLocation, node: &Node, comment: &str, )

Source§

impl CodeBuilder<'_>

Source

pub fn spill_required_registers( &mut self, node: &Node, comment: &str, ) -> ArgumentAndTempScope

Source

pub fn emit_restore_region( &mut self, region: SpilledRegisterRegion, output_destination_registers: &HashSet<u8>, node: &Node, comment: &str, )

Source§

impl<'a> CodeBuilder<'a>

Source

pub fn new( state: &'a mut CodeGenState, builder: &'a mut InstructionBuilder<'a>, variable_registers: SeqMap<usize, TypedRegister>, temp_registers: HwmTempRegisterPool, temp_allocator: StackFrameAllocator, options: CodeBuilderOptions, source_map_lookup: &'a SourceMapWrapper<'a>, ) -> Self

Source§

impl CodeBuilder<'_>

Source

pub fn total_aligned_frame_size(&self) -> FrameMemorySize

Source

pub fn patch_enter(&mut self, patch_position: PatchPosition)

Source

pub fn allocate_frame_space_and_return_absolute_pointer_reg( &mut self, ty: &BasicTypeRef, clear_it: bool, node: &Node, comment: &str, ) -> TypedRegister

Source

pub fn allocate_frame_space_and_return_pointer_location( &mut self, ty: &BasicTypeRef, clear_it: bool, node: &Node, comment: &str, ) -> PointerLocation

Source

pub fn allocate_frame_space_and_return_memory_location( &mut self, ty: &BasicTypeRef, clear_it: bool, node: &Node, comment: &str, ) -> MemoryLocation

Source

pub fn allocate_frame_space_and_return_destination_to_it( &mut self, ty: &BasicTypeRef, clear_it: bool, node: &Node, comment: &str, ) -> Place

Source

pub fn debug_expression(&mut self, expr: &Expression, description: &str)

Source§

impl CodeBuilder<'_>

Source

pub fn emit_enum_variant_to_memory_location( &mut self, target_memory_location: &AggregateMemoryLocation, enum_type: &TypeRef, variant_type: &EnumVariantType, sorted_expressions: &EnumLiteralExpressions, node: &Node, ctx: &Context, )

Source§

impl CodeBuilder<'_>

Source

pub fn emit_equality_to_bool_target( &mut self, dest_bool_reg: &TypedRegister, left_source: &TypedRegister, is_equal: bool, right_source: &TypedRegister, node: &Node, ctx: &Context, ) -> FlagState

Source§

impl CodeBuilder<'_>

Source

pub fn emit_expression( &mut self, output: &Place, expr: &Expression, ctx: &Context, )

The expression materializer! Transforms high-level expressions into their code representation, making sure each value finds its proper home in either a register or memory location.

§Optimization Magic

Uses Destination-Passing Style (DPS) to optimize code generation. Instead of creating temporary values and copying them around, we tell each expression exactly where its result should end up. This means we can often construct values directly in their final location, avoiding unnecessary copies and temporary allocations.

§Arguments
  • output - Where should our expression’s result live? (register or memory location)
  • expr - The expression we’re bringing to life
  • ctx - The context with all our compilation knowledge

If something needs temporary storage, we’ll handle that too.

Source§

impl CodeBuilder<'_>

Source

pub fn emit_initialize_memory_for_any_type( &mut self, memory_location: &MemoryLocation, node: &Node, comment: &str, )

Initialize memory for any type that might contain collections

This is the main public interface for memory initialization. It handles:

  • Direct collections: Initializes the collection metadata (capacity, etc.)
  • Container types: Recursively initializes any collections they contain
  • Scalar types: Does nothing (no initialization needed)

Use this function whenever you need to ensure that memory is properly initialized for any type that might contain collections, either directly or nested.

Source

pub fn emit_initialize_collection_metadata( &mut self, memory_location: &MemoryLocation, node: &Node, comment: &str, )

Initialize memory for a collection type at the specified location

This function is responsible for initializing the metadata for collection types:

  • For collections (Vec, Map, etc.), it sets the capacity field based on the type definition
  • Does NOT handle nested collections - use emit_initialize_collections_in_type for that

This is a specialized function for direct collection initialization only.

Source§

impl CodeBuilder<'_>

Source

pub fn emit_map_like_init_from_initialization_pair_list( &mut self, output_destination: &Place, elements: &[(Expression, Expression)], node: &Node, ctx: &Context, )

Source§

impl CodeBuilder<'_>

Source

pub fn emit_single_intrinsic_call( &mut self, target_reg: &Place, node: &Node, intrinsic_fn: &IntrinsicFunction, arguments: &[ArgumentExpression], ctx: &Context, )

Source

pub fn emit_intrinsic_map( &mut self, output_destination: &Place, intrinsic_fn: &IntrinsicFunction, self_ptr_reg: &PointerLocation, arguments: &[Expression], node: &Node, comment: &str, ctx: &Context, )

Source

pub fn emit_intrinsic_sparse( &mut self, output_destination: &Place, intrinsic_fn: &IntrinsicFunction, self_ptr_reg: &PointerLocation, arguments: &[Expression], node: &Node, comment: &str, ctx: &Context, )

Source

pub fn emit_intrinsic_grid( &mut self, target_destination: &Place, intrinsic_fn: &IntrinsicFunction, self_ptr_reg: &PointerLocation, arguments: &[Expression], node: &Node, comment: &str, ctx: &Context, )

Source

pub fn emit_intrinsic_transformer( &mut self, target_destination: &Place, intrinsic_fn: &IntrinsicFunction, self_addr: &PointerLocation, lambda: (Vec<VariableRef>, &Expression), node: &Node, ctx: &Context, )

Source

pub fn emit_single_intrinsic_call_with_self_destination( &mut self, target_destination: &Place, node: &Node, intrinsic_fn: &IntrinsicFunction, self_destination: Option<&Place>, arguments: &[ArgumentExpression], ctx: &Context, comment: &str, )

Source

pub fn emit_single_intrinsic_call_with_self( &mut self, target_destination: &Place, node: &Node, intrinsic_fn: &IntrinsicFunction, self_reg: Option<&TypedRegister>, arguments: &[ArgumentExpression], ctx: &Context, comment: &str, )

Source§

impl CodeBuilder<'_>

Source

pub fn emit_iterate_over_collection_with_lambda( &mut self, target_destination: &Place, node: &Node, source_collection_type: Collection, transformer: Transformer, source_collection_reg: &TypedRegister, lambda_tuple: (Vec<VariableRef>, &Expression), ctx: &Context, )

Generates code to iterate over a collection using a transformer (e.g., map, filter, filter_map) and a lambda expression. Handles creation of result vectors, iterator setup, lambda invocation, early exit logic, and result collection.

Steps:

  1. (Optional) Initialize a target vector for the result, if the transformer produces one.
  2. Initialize the iterator for the collection.
  3. Generate code to fetch the next element from the iterator.
  4. Spill lambda variables to protect them from being clobbered by function calls
  5. Inline the lambda code for the current element.
  6. Restore lambda variables from stack after lambda execution
  7. If the transformer supports early exit (e.g., filter, find), set the P flag based on the lambda result.
  8. Conditionally skip result insertion if early exit is triggered.
  9. (Optional) If applicable, insert the (possibly unwrapped) result into the target vector.
  10. Loop back to fetch the next element.
  11. Finalize iteration, handling any post-processing (e.g., normalizing boolean results).
§Parameters
  • node: The AST node for error reporting and code location.
  • collection_type: The type of collection being iterated.
  • transformer: The transformer operation (map, filter, find, fold, etc.).
  • collection_self_region: Memory region of the collection.
  • lambda_expression: The lambda expression to apply.
  • ctx: Code generation context. Contains the result target.
§Returns
  • Ok(()) on success, or an error if code generation fails.
§Errors

// TODO:

§Panics
  • If the lambda expression or its kind is not as expected (internal error).
Source§

impl CodeBuilder<'_>

Source

pub fn emit_unary_operator_logical( &mut self, dest_bool_reg: &TypedRegister, unary_operator: &UnaryOperator, ctx: &Context, ) -> FlagState

Source§

impl CodeBuilder<'_>

Source

pub fn map_subscript_helper( &mut self, map_header_location: &Place, map_type: &MapType, key_expression: &Expression, should_create_if_needed: bool, ctx: &Context, ) -> Place

Emits Swamp VM opcodes to calculate the memory address of an element within a map.

Source§

impl CodeBuilder<'_>

Source

pub fn emit_binary_operator_relational_i32_to_t_flag_only( &mut self, dest_bool_reg: &TypedRegister, left_source: &TypedRegister, binary_operator: &BinaryOperator, right_source: &TypedRegister, ) -> FlagState

Source

pub fn emit_binary_operator_relational_u8( &mut self, dest_bool_reg: &TypedRegister, left_source: &TypedRegister, binary_operator: &BinaryOperator, right_source: &TypedRegister, ) -> FlagState

Source

pub fn emit_binary_operator_relational_f32_to_t_flag_only( &mut self, dest_bool_reg: &TypedRegister, left_source: &TypedRegister, binary_operator: &BinaryOperator, right_source: &TypedRegister, ) -> FlagState

Source

pub fn emit_binary_operator_relational( &mut self, dest_bool_reg: &TypedRegister, left_source: &TypedRegister, binary_operator: &BinaryOperator, right_source: &TypedRegister, ) -> FlagState

Source§

impl CodeBuilder<'_>

Source

pub fn emit_aggregate_pointer_or_pointer_to_scalar_memory( &mut self, aggregate_or_scalar_expr: &Expression, ctx: &Context, ) -> TypedRegister

Make sure we have a pointer to something, no matter if it is a scalar or aggregate

Mostly (only?) used for making sure we have a key value memory region for Map to calculate a hash for (and copy this memory for inserting)

Source

pub fn emit_scalar_rvalue_or_pointer_to_temporary( &mut self, expr: &Expression, ctx: &Context, allow_temporary: bool, ) -> TypedRegister

Emits code to evaluate an expression and return a pointer register.

This function handles both regular expressions that can be materialized as scalar rvalues and expressions that need temporary memory storage (like initializer lists).

For expressions that need memory materialization:

  • If allow_temporary is true: Allocates temporary frame space, initializes it, and returns pointer
  • If allow_temporary is false: Falls back to emit_scalar_rvalue (may fail for some expressions)

For regular expressions:

  • Uses emit_scalar_rvalue to get the pointer directly
§Parameters
  • expr: The expression to evaluate
  • ctx: Code generation context
  • allow_temporary: Whether temporary storage is acceptable (false for mutable iteration)
Source

pub fn emit_scalar_rvalue( &mut self, expr: &Expression, ctx: &Context, ) -> TypedRegister

Emits code to evaluate an expression into a scalar rvalue.

In compiler terminology:

  • “emit” means to generate the machine code
  • “scalar” refers to single-value types (numbers, booleans, pointers) as opposed to aggregates
  • “rvalue” is a value-producing expression that can appear on the right side of an assignment

This method provides an optimized path for scalar values, avoiding the complexity of aggregate type handling in the general emit_expression. It’s particularly important for efficient code generation of expressions that must produce values (rvalues) rather than storage locations (lvalues).

Basically, for aggregate types, it shouldn’t to materialize (copy) the aggregate value to a destination, but instead just provide a register pointing to the source location.

§Direct Register Access

The following cases can return a register without materialization:

  • Variable access (returns the existing register)
  • Constants (the memory location can be materialized into a register)
  • Some scalar literals (can be materialized directly into a register)
§Register Allocation

For other expressions that can’t provide a direct register, a temporary register is allocated and the expression is evaluated into it.

§Examples in Compiler Terms
// Binary operations need rvalues for both operands
let left_reg = emit_scalar_rvalue(&binary_op.left);   // rvalue needed
let right_reg = emit_scalar_rvalue(&binary_op.right); // rvalue needed

// Assignment needs an lvalue on left, rvalue on right
let target = emit_lvalue(&assign.left);        // lvalue needed
let value = emit_scalar_rvalue(&assign.right); // rvalue needed
Source§

impl CodeBuilder<'_>

Source

pub fn sparse_subscript_helper( &mut self, vec_header_location: &Place, analyzed_element_type: &TypeRef, int_expr: &Expression, ctx: &Context, ) -> Place

Source

pub fn sparse_subscript_helper_helper( &mut self, sparse_header_location: &Place, analyzed_element_type: &TypeRef, int_expr: &Expression, ctx: &Context, ) -> PointerLocation

Source§

impl CodeBuilder<'_>

Source

pub fn emit_statement(&mut self, expr: &Expression, ctx: &Context)

Source§

impl CodeBuilder<'_>

Source

pub fn emit_check_that_known_len_is_less_or_equal_to_capacity( &mut self, destination_memory_location: &MemoryLocation, len: usize, node: &Node, comment: &str, ) -> TypedRegister

Source

pub fn emit_copy_value_between_places( &mut self, output_place: &Place, value_source: &Place, node: &Node, comment: &str, )

Source§

impl CodeBuilder<'_>

Source§

impl CodeBuilder<'_>

Source

pub fn vec_subscript_helper( &mut self, vec_header_location: &Place, analyzed_element_type: &TypeRef, int_expr: &Expression, ctx: &Context, ) -> Place

Emits Swamp VM opcodes to calculate the memory address of an element within an array.

The function targets a vec-like structured with a u16 length prefix followed by contiguous element data in memory. It uses the provided int_expression as the index for the lookup. Calls the subscript_helper_from_location_to_location to emit the bounds checking.

Source

pub fn emit_vec_subscript_range_helper( &mut self, destination_memory_location: &Place, source_memory_location: &Place, range_expr: &Expression, node: &Node, comment: &str, ctx: &Context, )

Source

pub fn grid_subscript_helper_helper( &mut self, grid_header_location: &Place, analyzed_element_type: &TypeRef, x_int_expr: &Expression, y_int_expr: &Expression, ctx: &Context, ) -> PointerLocation

Source

pub fn vec_subscript_helper_helper( &mut self, vec_header_location: &Place, analyzed_element_type: &TypeRef, int_expr: &Expression, ctx: &Context, ) -> PointerLocation

Auto Trait Implementations§

§

impl<'a> Freeze for CodeBuilder<'a>

§

impl<'a> RefUnwindSafe for CodeBuilder<'a>

§

impl<'a> !Send for CodeBuilder<'a>

§

impl<'a> !Sync for CodeBuilder<'a>

§

impl<'a> Unpin for CodeBuilder<'a>

§

impl<'a> !UnwindSafe for CodeBuilder<'a>

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