pub trait Indentable: Sized + Display {
// Provided methods
fn indented(self, indent: &str) -> Indented<'_, Self> { ... }
fn indented_skip_initial(self, indent: &str) -> IndentedSkipIntial<'_, Self> { ... }
}
Expand description
Methods for adapting Display
objects to indent themselves when printed.
Provided Methods§
Sourcefn indented(self, indent: &str) -> Indented<'_, Self>
fn indented(self, indent: &str) -> Indented<'_, Self>
Wrap this object so that its Display
representation is indented
with the given indent
. Each non-empty line of the formatted output
will be prefixed with the indent.
§Example:
use indent_write::indentable::Indentable;
let content = "Line 1\nLine 2\n\nLine 3\n";
let indented = content.indented(" ");
let result = indented.to_string();
assert_eq!(result, " Line 1\n Line 2\n\n Line 3\n");
Sourcefn indented_skip_initial(self, indent: &str) -> IndentedSkipIntial<'_, Self>
fn indented_skip_initial(self, indent: &str) -> IndentedSkipIntial<'_, Self>
Wrap this object so that its Display
representation is indented
with the given indent
. Each non-empty line except for the first
of the formatted output will be prefixed with the indent.
§Example:
use indent_write::indentable::Indentable;
let content = "Line 1\nLine 2\n\nLine 3\n";
let indented = content.indented_skip_initial(" ");
let result = indented.to_string();
assert_eq!(result, "Line 1\n Line 2\n\n Line 3\n");
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.