Trait SimpleEnclose

Source
pub trait SimpleEnclose {
Show 14 methods // Required method fn enclose_in_chars( &self, start: char, end: char, prefix: Option<&str>, escape_char: Option<char>, ) -> String; // Provided methods fn enclose_escaped( &self, start: char, end: char, escape_char: Option<char>, ) -> String { ... } fn enclose(&self, start: char, end: char) -> String { ... } fn enclose_safe(&self, start: char, end: char) -> String { ... } fn wrap_escaped(&self, opening: char, escape_char: Option<char>) -> String { ... } fn wrap(&self, opening: char) -> String { ... } fn wrap_safe(&self, opening: char) -> String { ... } fn in_parentheses(&self, prefix: Option<&str>) -> String { ... } fn parenthesize(&self) -> String { ... } fn parenthesize_safe(&self) -> String { ... } fn double_quotes(&self) -> String { ... } fn single_quotes(&self) -> String { ... } fn double_quotes_safe(&self) -> String { ... } fn single_quotes_safe(&self) -> String { ... }
}
Expand description

Traits with extension emthods to wrap strings in bounding characters

Required Methods§

Source

fn enclose_in_chars( &self, start: char, end: char, prefix: Option<&str>, escape_char: Option<char>, ) -> String

Enclose in a start and an end character with an optional prefix before the main content but after the first character This is a common syntactical pattern in many markup and programming languages the closing character will be the same opening character The optional escape character is inserted before occurrences of the end character unless the preceding character is the escape character itself to avoid double escaping of pre-escaped strings

Provided Methods§

Source

fn enclose_escaped( &self, start: char, end: char, escape_char: Option<char>, ) -> String

Enclose in a start and an end character with an optional prefix after the first character

Source

fn enclose(&self, start: char, end: char) -> String

Enclose in a start and an end character with an optional prefix after the first character

Source

fn enclose_safe(&self, start: char, end: char) -> String

Enclose in a start and an end character with an optional prefix after the first character escaped where necessary with a backslash \

Source

fn wrap_escaped(&self, opening: char, escape_char: Option<char>) -> String

Wrap a string in a pair of characters, with the closing character matching the first character if it a parenthesis (round bracket), angle bracket, (square) bracket or curly brace. Otherwise the closing character will be the same opening character The optional escape character is inserted before occurrences of the end character unless the preceding character is the escape character itself to avoid double escaping of pre-escaped strings

Source

fn wrap(&self, opening: char) -> String

wrap a string in the same opening and closing character

Source

fn wrap_safe(&self, opening: char) -> String

Wrap in matching characters escaped by a backslash \

Source

fn in_parentheses(&self, prefix: Option<&str>) -> String

wrap in parentheses (sound brackets) with an optional prefix before the main content

Source

fn parenthesize(&self) -> String

wrap in parentheses (sound brackets)

Source

fn parenthesize_safe(&self) -> String

wrap in parentheses (sound brackets)

Source

fn double_quotes(&self) -> String

wrap in parentheses (sound brackets)

Source

fn single_quotes(&self) -> String

Wrap in single quotes

Source

fn double_quotes_safe(&self) -> String

Wrap in double quotes with escaped quotes in the content

Source

fn single_quotes_safe(&self) -> String

Wrap in single quotes with escaped quotes in the content

Implementations on Foreign Types§

Source§

impl SimpleEnclose for str

Implement the base method for &str/String

Source§

fn enclose_in_chars( &self, start: char, end: char, prefix: Option<&str>, escape_char: Option<char>, ) -> String

Implementors§