pub struct String { /* private fields */ }
Available on crate feature alloc only.
Expand description

An attributed version of alloc::string::String which has a specific Style associated with each character.

The main interfaces to create an instance of this are stylish::format! and impl Write for String, and to inspect the content impl Display for String.

You can create an instance via stylish::format!:

let _: stylish::String = stylish::format!("Hello {:(fg=green)}!", "World");

You can append extra data via stylish::write!:

use stylish::Write;

let mut s = stylish::String::new();
stylish::write!(s, "{:(fg=magenta)}", "fuchsia")?;

To use the attributed data you must then write this string to a sink using the {:s} trait-selector.

use stylish::Write;

let mut s = stylish::format!("Hello {:(fg=green)}!", "World");
stylish::write!(s, " Is it {:(fg=magenta)} or?", "fuchsia")?;

assert_eq!(
    stylish::html::format!("{:s}", s),
    "Hello <span style=color:green>World</span>! \
    Is it <span style=color:magenta>fuchsia</span> or?",
);

Implementations

Create an empty String.

assert_eq!(stylish::html::format!("{:s}", stylish::String::new()), "");

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Formats the value using the given formatter. Read more

Writes a string slice with a particular Style into this writer, returning whether the write succeeded. Read more

Writes a char with a particular Style into this writer, returning whether the write succeeded. Read more

Glue for usage of the stylish::write! macro with implementors of this trait. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.