StringWidthOptionsBuilder

Struct StringWidthOptionsBuilder 

Source
pub struct StringWidthOptionsBuilder { /* private fields */ }
Expand description

Builder for StringWidthOptions following the builder pattern

Provides a fluent API for configuring string width calculation options.

§Examples

use string_width::{StringWidthOptions, AmbiguousWidthTreatment};

// Basic usage
let options = StringWidthOptions::builder()
    .count_ansi(true)
    .ambiguous_as_wide()
    .build();

// All options
let options = StringWidthOptions::builder()
    .count_ansi(false)
    .ambiguous_width(AmbiguousWidthTreatment::Narrow)
    .build();

Implementations§

Source§

impl StringWidthOptionsBuilder

Source

pub fn new() -> Self

Creates a new builder with default values

This is equivalent to calling StringWidthOptionsBuilder::default().

§Examples
use string_width::{StringWidthOptions, StringWidthOptionsBuilder};

let builder = StringWidthOptions::builder();
// or
let builder = StringWidthOptionsBuilder::new();
Source

pub fn count_ansi(self, count_ansi: bool) -> Self

Sets whether to count ANSI escape sequences in width calculation

When set to true, ANSI escape sequences will be included in the width calculation. When false (default), they are stripped and ignored.

§Arguments
  • count_ansi - Whether to count ANSI sequences
§Examples
use string_width::{StringWidthOptions, string_width_with_options};

let options = StringWidthOptions::builder()
    .count_ansi(true)
    .build();

// ANSI sequences are counted
assert_eq!(string_width_with_options("\x1b[31mRed\x1b[0m", options), 12);
Source

pub fn ambiguous_width(self, ambiguous_width: AmbiguousWidthTreatment) -> Self

Sets how ambiguous width characters should be treated

Allows explicit control over ambiguous width character treatment.

§Arguments
  • ambiguous_width - The treatment strategy for ambiguous characters
§Examples
use string_width::{StringWidthOptions, AmbiguousWidthTreatment, string_width_with_options};

let options = StringWidthOptions::builder()
    .ambiguous_width(AmbiguousWidthTreatment::Wide)
    .build();

assert_eq!(string_width_with_options("±", options), 2);
Source

pub fn ambiguous_as_narrow(self) -> Self

Sets ambiguous width characters to be treated as narrow (convenience method)

This is a convenience method equivalent to calling .ambiguous_width(AmbiguousWidthTreatment::Narrow).

§Examples
use string_width::{StringWidthOptions, string_width_with_options};

let options = StringWidthOptions::builder()
    .ambiguous_as_narrow()
    .build();

assert_eq!(string_width_with_options("±", options), 1);
Source

pub fn ambiguous_as_wide(self) -> Self

Sets ambiguous width characters to be treated as wide (convenience method)

This is a convenience method equivalent to calling .ambiguous_width(AmbiguousWidthTreatment::Wide).

§Examples
use string_width::{StringWidthOptions, string_width_with_options};

let options = StringWidthOptions::builder()
    .ambiguous_as_wide()
    .build();

assert_eq!(string_width_with_options("±", options), 2);
Source

pub fn build(self) -> StringWidthOptions

Builds the final StringWidthOptions instance

Consumes the builder and returns the configured StringWidthOptions.

§Examples
use string_width::StringWidthOptions;

let options = StringWidthOptions::builder()
    .count_ansi(true)
    .ambiguous_as_wide()
    .build();

Trait Implementations§

Source§

impl Clone for StringWidthOptionsBuilder

Source§

fn clone(&self) -> StringWidthOptionsBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for StringWidthOptionsBuilder

Source§

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

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

impl Default for StringWidthOptionsBuilder

Source§

fn default() -> StringWidthOptionsBuilder

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

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.