pub struct Padded<L: Localize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> { /* private fields */ }Implementations§
Source§impl<L: Localize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>
impl<L: Localize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>
Sourcepub const fn new(message: L) -> Self
pub const fn new(message: L) -> Self
Examples found in repository?
examples/layout.rs (line 15)
7fn main() {
8 let items = vec!["item 1", "item 2", "item 3", "item 4"];
9 let message = "a secret message";
10
11 // Create different layouts
12 let single_newline: Lines<&str, 1> = Lines::new(items.clone());
13 let double_newlines: Lines<&str, 2> = Lines::new(items.clone());
14
15 let vertical_padding: Padded<&str, 1, 0> = Padded::new(message);
16 let horizontal_padding: Padded<&str, 0, 4> = Padded::new(message);
17 let combined_padding: Padded<&str, 1, 4> = Padded::new(message);
18
19 let padded_newlines: Lines<Padded<&str, 0, 4>, 1> =
20 Lines::new(items.iter().map(|item| Padded::new(*item)).collect());
21
22 // Localize these layouts
23 let layouts: [(&str, Box<dyn Localize>); 6] = [
24 ("Single newline", Box::new(single_newline)),
25 ("Double newlines", Box::new(double_newlines)),
26 ("Vertical padding", Box::new(vertical_padding)),
27 ("Horizontal padding", Box::new(horizontal_padding)),
28 ("Combined padding", Box::new(combined_padding)),
29 ("Padded newlines", Box::new(padded_newlines)),
30 ];
31
32 let context = Context::new(locale!("en-US"), true);
33 let mut buffer = String::new();
34
35 // Print each layout with a separator to make things clear
36 for (name, layout) in layouts {
37 buffer.clear();
38 layout.localize(&context, &mut buffer);
39
40 println!("----- {name} -----");
41 println!("{buffer}");
42 }
43}Trait Implementations§
Source§impl<L: Clone + Localize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Clone for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>
impl<L: Clone + Localize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Clone for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>
Source§impl<L: Debug + Localize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Debug for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>
impl<L: Debug + Localize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Debug for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>
Source§impl<L: Localize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Localize for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>
impl<L: Localize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Localize for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>
Auto Trait Implementations§
impl<L, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Freeze for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>where
L: Freeze,
impl<L, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> RefUnwindSafe for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>where
L: RefUnwindSafe,
impl<L, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Send for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>where
L: Send,
impl<L, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Sync for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>where
L: Sync,
impl<L, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Unpin for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>where
L: Unpin,
impl<L, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> UnsafeUnpin for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>where
L: UnsafeUnpin,
impl<L, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> UnwindSafe for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>where
L: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more