Skip to main content

Padded

Struct Padded 

Source
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>

Source

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>

Source§

fn clone(&self) -> Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<L: Debug + Localize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Debug for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<L: Localize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Localize for Padded<L, VERTICAL_PADDING, HORIZONTAL_PADDING>

Source§

fn canonical_locale(&self) -> Locale

Source§

fn available_locales(&self) -> Vec<Locale>

Source§

fn localize(&self, context: &Context, buffer: &mut String)

Source§

impl<M: Localize + Serialize, const VERTICAL_PADDING: usize, const HORIZONTAL_PADDING: usize> Serialize for Padded<M, VERTICAL_PADDING, HORIZONTAL_PADDING>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.