resize_slice2

Crates.ioresize_slice2
lib.rsresize_slice2
version0.2.0
sourcesrc
created_at2023-01-09 05:21:55.090227
updated_at2023-01-15 17:36:21.684355
descriptionResize a slice given a larger slice in safe Rust
homepage
repositoryhttps://github.com/benthillerkus/resize_slice
max_upload_size
id754130
size18,003
Bent Hillerkus (benthillerkus)

documentation

README

license: MIT build status docs crate version

resize slice (2)

Enlarge and shrink slices (given a larger slice) in safe Rust.

This is done by expressing the new slice as a slice of the source slice -- this way you can also extend the lifetime to the sources lifetime.

Example

use resize_slice2::ResizeSlice;
let source = &["a", "b", "c", "d", "e", "f"];
let slice = &source[1..4];
assert_eq!(slice, &["b", "c", "d"]);
let resized = slice.try_resize(source, 0..1).unwrap();
assert_eq!(resized, &["b", "c", "d", "e"]);

So a range of 1..-1 would move the start one to the right and move the end one to the left.

source: |------------------------|
slice:             |-------|
result:              |---|

A range of 1.. would move the start one to the right and fully expand the end.

source: |------------------------|
slice:             |-------|
result:              |-----------|

A range of 0..0 would return the same slice.

source: |------------------------|
slice:            |-------|
result:           |-------|
Commit count: 15

cargo fmt