Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resolver = "3"

[package]
name = "padder"
version = "2.0.0"
version = "2.0.1"
edition = "2024"
description = "A highly efficient Rust crate for padding data during runtime."
authors = [
Expand Down
38 changes: 10 additions & 28 deletions src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ impl Source for &str {
type Symbol = char;
type Buffer = String;
type Output = String;
type Slice<'a> = Self;
type Slice<'a>
= Self
where
Self: 'a;

/// Truncates the &str to match the specified `width` according to the specified alignment
/// `mode`.
Expand Down Expand Up @@ -98,8 +101,6 @@ impl Source for &str {
/// Pads or truncates the &str to match the specified `width` according to the specified
/// alignment `mode`.
///
/// See [`truncate_to_fit`] for details on how truncating is performed.
///
/// If the &str is longer than `width` (in utf8 chars), it will be truncated.
///
/// If the &str is shorter than `width`, it will be padded using the `symbol`.
Expand All @@ -121,7 +122,6 @@ impl Source for &str {
/// assert_eq!(18, o2.capacity()); // these utf8 chars use more bytes :)
/// assert_eq!(18, o2.len());
/// ```
/// [`truncate_to_fit`]: Self::truncate_to_fit
fn pad(&self, width: usize, mode: Alignment, symbol: Self::Symbol) -> Self::Output {
let n_chars_original: usize = self.chars().count();
if width < n_chars_original {
Expand All @@ -147,8 +147,6 @@ impl Source for &str {
/// Pads or truncates the &str in-place to match the specified `width` according to the
/// specified alignment `mode` by writing into the provided `buffer`.
///
/// See [`truncate_to_fit`] for details on how truncating is performed.
///
/// If the &str is longer than `width` (in utf8 chars), it will be truncated.
///
/// If the &str is shorter than `width`, it will be padded using the `symbol`.
Expand All @@ -175,7 +173,6 @@ impl Source for &str {
/// assert_eq!(21, buf.capacity());
/// assert_eq!(21, buf.len());
/// ```
/// [`truncate_to_fit`]: Self::truncate_to_fit
fn pad_to_buffer(
&self,
width: usize,
Expand Down Expand Up @@ -206,7 +203,10 @@ impl Source for String {
type Symbol = char;
type Buffer = Self;
type Output = Self;
type Slice<'a> = &'a str;
type Slice<'a>
= &'a str
where
Self: 'a;

/// Truncates the string to match the specified `width` according to the specified alignment
/// `mode`.
Expand Down Expand Up @@ -255,8 +255,6 @@ impl Source for String {

/// Pads or truncates the string to match the specified `width` according to the specified alignment `mode`.
///
/// See [`truncate_to_fit`] for details on how truncating is performed.
///
/// If the string is longer than `width` (in utf8 chars), it will be truncated.
///
/// If the string is shorter than `width`, it will be padded using the `symbol`.
Expand All @@ -272,7 +270,6 @@ impl Source for String {
/// assert_eq!(18, o.capacity()); // '風' is 3 bytes
/// assert_eq!(18, o.len());
/// ```
/// [`truncate_to_fit`]: Self::truncate_to_fit
fn pad(&self, width: usize, mode: Alignment, symbol: Self::Symbol) -> Self::Output {
let n_chars_original: usize = self.chars().count();
if width < n_chars_original {
Expand Down Expand Up @@ -300,8 +297,6 @@ impl Source for String {
/// Pads or truncates the string in-place to match the specified `width` according to the
/// specified alignment `mode` by writing into the provided `buffer`.
///
/// See [`truncate_to_fit`] for details on how truncating is performed.
///
/// If the string is longer than `width` (in utf8 chars), it will be truncated.
///
/// If the string is shorter than `width`, it will be padded using the `symbol`.
Expand All @@ -328,7 +323,6 @@ impl Source for String {
/// assert_eq!(10, buf.capacity());
/// assert_eq!(10, buf.len());
/// ```
/// [`truncate_to_fit`]: Self::truncate_to_fit
fn pad_to_buffer(
&self,
width: usize,
Expand Down Expand Up @@ -365,7 +359,7 @@ where
type Slice<'a>
= &'a [T]
where
T: 'a;
Self: 'a;

/// Truncates the vector to match the specified `width` according to the specified alignment `mode`.
/// - [`Alignment::Left`]: truncates from the right.
Expand All @@ -385,8 +379,6 @@ where

/// Pads or truncates the vector to match the specified `width` according to the specified alignment `mode`.
///
/// See [`truncate_to_fit`] for details on how truncating is performed.
///
/// If the vector is longer than `width` (in number of items), it will be truncated.
///
/// If the vector is shorter than `width`, it will be padded using the `symbol`.
Expand All @@ -402,7 +394,6 @@ where
/// assert_eq!(5, o.capacity());
/// assert_eq!(5, o.len());
/// ```
/// [`truncate_to_fit`]: Self::truncate_to_fit
fn pad(&self, width: usize, mode: Alignment, symbol: Self::Symbol) -> Self::Output {
if width < self.len() {
return self.truncate_to_fit(width, mode).to_vec();
Expand All @@ -426,8 +417,6 @@ where
/// Pads or truncates the vector in-place to match the specified `width` according to the
/// specified alignment `mode` by writing into the provided `buffer`.
///
/// See [`truncate_to_fit`] for details on how truncating is performed.
///
/// If the vector is longer than `width` (in number of items), it will be truncated.
///
/// If the vector is shorter than `width`, it will be padded using the `symbol`.
Expand Down Expand Up @@ -473,7 +462,6 @@ where
/// assert_eq!(expected.len(), buf.len());
/// }
/// ```
/// [`truncate_to_fit`]: Self::truncate_to_fit
fn pad_to_buffer(
&self,
width: usize,
Expand Down Expand Up @@ -510,7 +498,7 @@ where
type Slice<'a>
= &'a [T]
where
T: 'a;
Self: 'a;

/// Truncates the slice to match the specified `width` according to the specified alignment `mode`.
/// - [`Alignment::Left`]: truncates from the right.
Expand All @@ -530,8 +518,6 @@ where

/// Pads or truncates the slice to match the specified `width` according to the specified alignment `mode`.
///
/// See [`truncate_to_fit`] for details on how truncating is performed.
///
/// If the slice is longer than `width` (in number of items), it will be truncated.
///
/// If the slice is shorter than `width`, it will be padded using the `symbol`.
Expand All @@ -547,7 +533,6 @@ where
/// assert_eq!(9, o.capacity());
/// assert_eq!(9, o.len());
/// ```
/// [`truncate_to_fit`]: Self::truncate_to_fit
fn pad(&self, width: usize, mode: Alignment, symbol: Self::Symbol) -> Self::Output {
if width < self.len() {
return self.truncate_to_fit(width, mode).to_vec();
Expand All @@ -570,8 +555,6 @@ where
/// Pads or truncates the slice in-place to match the specified `width` according to the
/// specified alignment `mode` by writing into the provided `buffer`.
///
/// See [`truncate_to_fit`] for details on how truncating is performed.
///
/// If the slice is longer than `width` (in number of items), it will be truncated.
///
/// If the slice is shorter than `width`, it will be padded using the `symbol`.
Expand All @@ -593,7 +576,6 @@ where
/// assert_eq!(7, o.capacity());
/// assert_eq!(7, o.len());
/// ```
/// [`truncate_to_fit`]: Self::truncate_to_fit
fn pad_to_buffer(
&self,
width: usize,
Expand Down
Loading