Skip to content
Open
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ bincode = ["dep:bincode"]

[dev-dependencies]
serde_json = "1"

[lints.clippy]
missing_const_for_fn = "warn"
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl<T> NonEmpty<T> {
/// *head *= 42;
/// assert_eq!(non_empty.first(), &42);
/// ```
pub fn first_mut(&mut self) -> &mut T {
pub const fn first_mut(&mut self) -> &mut T {
&mut self.head
}

Expand Down Expand Up @@ -339,17 +339,17 @@ impl<T> NonEmpty<T> {
}

/// Get the length of the list.
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.tail.len() + 1
}

/// Gets the length of the list as a NonZeroUsize.
pub fn len_nonzero(&self) -> NonZeroUsize {
pub const fn len_nonzero(&self) -> NonZeroUsize {
unsafe { NonZeroUsize::new_unchecked(self.tail.len().saturating_add(1)) }
}

/// Get the capacity of the list.
pub fn capacity(&self) -> NonZeroUsize {
pub const fn capacity(&self) -> NonZeroUsize {
NonZeroUsize::MIN.saturating_add(self.tail.capacity())
}

Expand Down
4 changes: 2 additions & 2 deletions src/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ pub struct NonEmpty<T>(super::NonEmpty<T>);

impl<T> NonEmpty<T> {
/// Get the length of the list.
pub fn len(&self) -> NonZeroUsize {
pub const fn len(&self) -> NonZeroUsize {
unsafe { NonZeroUsize::new_unchecked(self.0.tail.len() + 1) }
}

/// Get the capacity of the list.
pub fn capacity(&self) -> NonZeroUsize {
pub const fn capacity(&self) -> NonZeroUsize {
unsafe { NonZeroUsize::new_unchecked(self.0.tail.capacity() + 1) }
}

Expand Down