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, 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> for AlignmentStrategy
impl<R> CellOption<R> for AlignmentStrategy
Source§fn change_cell(&mut self, table: &mut Table<R>, entity: Entity)
fn change_cell(&mut self, table: &mut Table<R>, entity: Entity)
Modification function of a single cell.
Source§impl Clone for AlignmentStrategy
impl Clone for AlignmentStrategy
Source§fn clone(&self) -> AlignmentStrategy
fn clone(&self) -> AlignmentStrategy
Returns a copy 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 moreAuto 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