Skip to content

Commit 79e8b2f

Browse files
committed
Release v6.2.2
1 parent 36f9d82 commit 79e8b2f

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

CHANGELOG

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v6.2.2
2+
- Improve documentation.
3+
14
## v6.2.1
25
- Add `prefix_with` and `suffix_with`.
36
- Bump dependencies.

src/lib.rs

+32-26
Original file line numberDiff line numberDiff line change
@@ -341,68 +341,74 @@ where
341341
slice2array(slice).unwrap()
342342
}
343343

344-
/// Prefixes the given element to the given slice to make it a fixed-size array of length `N`.
344+
/// Prefixes the given element to the given array/slice/vector to make it a fixed-size array of
345+
/// length `N`.
345346
///
346-
/// If the length of the slice is already equal to `N`, it returns the slice as a fixed-size array.
347-
/// If the length of the slice is greater than `N`, it returns the first `N` elements of the slice
348-
/// as a fixed-size array.
349-
/// If the length of the slice is less than `N`, it creates a new fixed-size array of length `N` and
350-
/// copies the slice into it, padding the remaining elements with the given element.
347+
/// If the length of the array/slice/vector is already equal to `N`, it returns the
348+
/// array/slice/vector as a fixed-size array.
349+
/// If the length of the array/slice/vector is greater than `N`, it returns the first `N` elements
350+
/// of the array/slice/vector as a fixed-size array.
351+
/// If the length of the array/slice/vector is less than `N`, it creates a new fixed-size array of
352+
/// length `N` and copies the array/slice/vector into it, padding the remaining elements with the
353+
/// given element.
351354
///
352355
/// # Examples
353356
/// ```
354357
/// assert_eq!(array_bytes::prefix_with::<_, _, 4>([1, 2, 3, 4], 0), [1, 2, 3, 4]);
355358
/// assert_eq!(array_bytes::prefix_with::<_, _, 4>([1, 2, 3, 4, 5, 6], 0), [1, 2, 3, 4]);
356359
/// assert_eq!(array_bytes::prefix_with::<_, _, 5>([1, 2, 3], 0), [0, 0, 1, 2, 3]);
357360
/// ```
358-
pub fn prefix_with<S, T, const N: usize>(slice: S, element: T) -> [T; N]
361+
pub fn prefix_with<A, T, const N: usize>(any: A, element: T) -> [T; N]
359362
where
360-
S: AsRef<[T]>,
363+
A: AsRef<[T]>,
361364
T: Copy,
362365
{
363-
let s = slice.as_ref();
366+
let a = any.as_ref();
364367

365-
match s.len().cmp(&N) {
366-
Ordering::Equal => slice2array_unchecked(s),
367-
Ordering::Greater => slice2array_unchecked(&s[..N]),
368+
match a.len().cmp(&N) {
369+
Ordering::Equal => slice2array_unchecked(a),
370+
Ordering::Greater => slice2array_unchecked(&a[..N]),
368371
Ordering::Less => {
369372
let mut padded = [element; N];
370373

371-
padded[N - s.len()..].copy_from_slice(s);
374+
padded[N - a.len()..].copy_from_slice(a);
372375

373376
padded
374377
},
375378
}
376379
}
377380

378-
/// Suffixes the given element to the given slice to make it a fixed-size array of length `N`.
381+
/// Suffixes the given element to the given array/slice/vector to make it a fixed-size array of
382+
/// length `N`.
379383
///
380-
/// If the length of the slice is already equal to `N`, it returns the slice as a fixed-size array.
381-
/// If the length of the slice is greater than `N`, it returns the first `N` elements of the slice
382-
/// as a fixed-size array. If the length of the slice is less than `N`, it creates a new fixed-size
383-
/// array of length `N` and copies the slice into it, padding the remaining elements with the given
384-
/// element.
384+
/// If the length of the array/slice/vector is already equal to `N`, it returns the
385+
/// array/slice/vector as a fixed-size array.
386+
/// If the length of the array/slice/vector is greater than `N`, it returns the first `N` elements
387+
/// of the array/slice/vector as a fixed-size array.
388+
/// If the length of the array/slice/vector is less than `N`, it creates a new fixed-size array of
389+
/// length `N` and copies the array/slice/vector into it, padding the remaining elements with the
390+
/// given element.
385391
///
386392
/// # Examples
387393
/// ```
388394
/// assert_eq!(array_bytes::suffix_with::<_, _, 4>([1, 2, 3, 4], 0), [1, 2, 3, 4]);
389395
/// assert_eq!(array_bytes::suffix_with::<_, _, 4>([1, 2, 3, 4, 5, 6], 0), [1, 2, 3, 4]);
390396
/// assert_eq!(array_bytes::suffix_with::<_, _, 5>([1, 2, 3], 0), [1, 2, 3, 0, 0]);
391397
/// ```
392-
pub fn suffix_with<S, T, const N: usize>(slice: S, element: T) -> [T; N]
398+
pub fn suffix_with<A, T, const N: usize>(any: A, element: T) -> [T; N]
393399
where
394-
S: AsRef<[T]>,
400+
A: AsRef<[T]>,
395401
T: Copy,
396402
{
397-
let s = slice.as_ref();
403+
let a = any.as_ref();
398404

399-
match s.len().cmp(&N) {
400-
Ordering::Equal => slice2array_unchecked(s),
401-
Ordering::Greater => slice2array_unchecked(&s[..N]),
405+
match a.len().cmp(&N) {
406+
Ordering::Equal => slice2array_unchecked(a),
407+
Ordering::Greater => slice2array_unchecked(&a[..N]),
402408
Ordering::Less => {
403409
let mut padded = [element; N];
404410

405-
padded[..s.len()].copy_from_slice(s);
411+
padded[..a.len()].copy_from_slice(a);
406412

407413
padded
408414
},

0 commit comments

Comments
 (0)