pub enum AlignmentStrategy {
PerCell,
PerLine,
}
Expand description
AlignmentStrategy
is a responsible for a flow how we apply an alignment.
It mostly matters for multiline strings.
§Examples
use tabled::{
Table,
settings::{
Style, Modify, Alignment, object::Segment,
formatting::{AlignmentStrategy, TrimStrategy}
}
};
// sample_from: https://opensource.adobe.com/Spry/samples/data_region/JSONDataSetSample.html
let json = r#"
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters": {
"batter": [
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
]
},
"topping": [
{ "id": "5001", "type": "None" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
}"#;
let mut table = Table::new(&[json]);
table
.with(Style::modern())
.with(Modify::new(Segment::all()).with(Alignment::right()))
.with(Modify::new(Segment::all()).with(TrimStrategy::None));
println!("{}", table);
assert_eq!(
format!("\n{}", table),
r#"
┌───────────────────────────────────────────────────────────────┐
│ &str │
├───────────────────────────────────────────────────────────────┤
│ │
│ { │
│ "id": "0001", │
│ "type": "donut", │
│ "name": "Cake", │
│ "ppu": 0.55, │
│ "batters": { │
│ "batter": [ │
│ { "id": "1001", "type": "Regular" }, │
│ { "id": "1002", "type": "Chocolate" }, │
│ ] │
│ }, │
│ "topping": [ │
│ { "id": "5001", "type": "None" }, │
│ { "id": "5006", "type": "Chocolate with Sprinkles" }, │
│ { "id": "5003", "type": "Chocolate" }, │
│ { "id": "5004", "type": "Maple" } │
│ ] │
│ } │
└───────────────────────────────────────────────────────────────┘"#);
table
.with(Modify::new(Segment::all()).with(AlignmentStrategy::PerCell))
.with(Modify::new(Segment::all()).with(TrimStrategy::Horizontal));
assert_eq!(
format!("\n{}", table),
r#"
┌───────────────────────────────────────────────────────────────┐
│ &str │
├───────────────────────────────────────────────────────────────┤
│ │
│ { │
│ "id": "0001", │
│ "type": "donut", │
│ "name": "Cake", │
│ "ppu": 0.55, │
│ "batters": { │
│ "batter": [ │
│ { "id": "1001", "type": "Regular" }, │
│ { "id": "1002", "type": "Chocolate" }, │
│ ] │
│ }, │
│ "topping": [ │
│ { "id": "5001", "type": "None" }, │
│ { "id": "5006", "type": "Chocolate with Sprinkles" }, │
│ { "id": "5003", "type": "Chocolate" }, │
│ { "id": "5004", "type": "Maple" } │
│ ] │
│ } │
└───────────────────────────────────────────────────────────────┘"#);
table.with(Modify::new(Segment::all()).with(AlignmentStrategy::PerLine));
assert_eq!(
format!("\n{}", table),
r#"
┌───────────────────────────────────────────────────────────────┐
│ &str │
├───────────────────────────────────────────────────────────────┤
│ │
│ { │
│ "id": "0001", │
│ "type": "donut", │
│ "name": "Cake", │
│ "ppu": 0.55, │
│ "batters": { │
│ "batter": [ │
│ { "id": "1001", "type": "Regular" }, │
│ { "id": "1002", "type": "Chocolate" }, │
│ ] │
│ }, │
│ "topping": [ │
│ { "id": "5001", "type": "None" }, │
│ { "id": "5006", "type": "Chocolate with Sprinkles" }, │
│ { "id": "5003", "type": "Chocolate" }, │
│ { "id": "5004", "type": "Maple" } │
│ ] │
│ } │
└───────────────────────────────────────────────────────────────┘"#);
Variants§
PerCell
Apply alignment for cell content as a whole.
PerLine
Apply alignment for each line of a cell content as a whole.
Trait Implementations§
Source§impl<R> CellOption<R, ColoredConfig> for AlignmentStrategy
impl<R> CellOption<R, ColoredConfig> for AlignmentStrategy
Source§fn change(self, _: &mut R, cfg: &mut ColoredConfig, entity: Entity)
fn change(self, _: &mut R, cfg: &mut ColoredConfig, entity: Entity)
Modification function of a certail part of a grid targeted by
Entity
.Source§fn hint_change(&self) -> Option<Entity>
fn hint_change(&self) -> Option<Entity>
A hint whether an
TableOption
is going to change table layout. Read moreSource§impl Clone for AlignmentStrategy
impl Clone for AlignmentStrategy
Source§fn clone(&self) -> AlignmentStrategy
fn clone(&self) -> AlignmentStrategy
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for AlignmentStrategy
impl Debug for AlignmentStrategy
Source§impl Ord for AlignmentStrategy
impl Ord for AlignmentStrategy
Source§fn cmp(&self, other: &AlignmentStrategy) -> Ordering
fn cmp(&self, other: &AlignmentStrategy) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for AlignmentStrategy
impl PartialEq for AlignmentStrategy
Source§impl PartialOrd for AlignmentStrategy
impl PartialOrd for AlignmentStrategy
Source§impl<R, D> TableOption<R, ColoredConfig, D> for AlignmentStrategy
impl<R, D> TableOption<R, ColoredConfig, D> for AlignmentStrategy
Source§fn change(self, records: &mut R, cfg: &mut ColoredConfig, _: &mut D)
fn change(self, records: &mut R, cfg: &mut ColoredConfig, _: &mut D)
The function modificaties of records and a grid configuration.
Source§fn hint_change(&self) -> Option<Entity>
fn hint_change(&self) -> Option<Entity>
A hint whether an
TableOption
is going to change table layout. Read moreSource§impl<R, D> TableOption<R, CompactMultilineConfig, D> for AlignmentStrategy
impl<R, D> TableOption<R, CompactMultilineConfig, D> for AlignmentStrategy
Source§fn change(self, _: &mut R, cfg: &mut CompactMultilineConfig, _: &mut D)
fn change(self, _: &mut R, cfg: &mut CompactMultilineConfig, _: &mut D)
The function modificaties of records and a grid configuration.
Source§fn hint_change(&self) -> Option<Entity>
fn hint_change(&self) -> Option<Entity>
A hint whether an
TableOption
is going to change table layout. Read moreimpl Copy for AlignmentStrategy
impl Eq for AlignmentStrategy
impl StructuralPartialEq for AlignmentStrategy
Auto Trait Implementations§
impl Freeze for AlignmentStrategy
impl RefUnwindSafe for AlignmentStrategy
impl Send for AlignmentStrategy
impl Sync for AlignmentStrategy
impl Unpin for AlignmentStrategy
impl UnwindSafe for AlignmentStrategy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more