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
impl StringWidthOptionsBuilder
Sourcepub fn new() -> Self
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();Sourcepub fn count_ansi(self, count_ansi: bool) -> Self
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);Sourcepub fn ambiguous_width(self, ambiguous_width: AmbiguousWidthTreatment) -> Self
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);Sourcepub fn ambiguous_as_narrow(self) -> Self
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);Sourcepub fn ambiguous_as_wide(self) -> Self
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);Sourcepub fn build(self) -> StringWidthOptions
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
impl Clone for StringWidthOptionsBuilder
Source§fn clone(&self) -> StringWidthOptionsBuilder
fn clone(&self) -> StringWidthOptionsBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more