Skip to content

infallible accessor methods to first and last byte #6

Description

@hubcycle

Provide the following methods for NonEmptyBz:

impl<T: AsRef<[u8]>> NonEmptyBz<T> {
	/// Returns the first byte of the contained value.
	pub fn first(&self) -> u8;

	/// Returns the last byte of the contained value.
	pub fn last(&self) -> u8;

	/// Returns the first byte and the remaining slice.
	///
	/// The remaining slice will be empty if the contained value has only one byte.
	pub fn split_first(&self) -> (u8, &[u8]);

	/// Returns the last byte and the remaining slice.
	///
	/// The remaining slice will be empty if the contained value has only one byte.
	pub fn split_last(&self) -> (u8, &[u8]);
}

unsafe code

There will be unsafe blocks to use the slice::get_unchecked method for maximum performance.

miri

Ensure all the edge cases are properly tested.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions