Skip to content
Draft
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
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ mod test_readme {
mod something {}
}

use std::str::FromStr;
use core::num::NonZero;
use core::str::FromStr;

use delegate::delegate;

Expand Down Expand Up @@ -77,7 +78,9 @@ impl NonEmptyString {

/// Is forwarded to the inner String.
/// See [`String::capacity`]
pub fn capacity(&self) -> usize;
#[try_into]
#[unwrap]
pub fn capacity(&self) -> NonZero<usize>;

/// Is forwarded to the inner String.
/// See [`String::reserve`]
Expand Down Expand Up @@ -123,7 +126,9 @@ impl NonEmptyString {

/// Is forwarded to the inner String.
/// See [`String::len`]
pub fn len(&self) -> usize;
#[try_into]
#[unwrap]
pub fn len(&self) -> NonZero<usize>;

/// Is forwarded to the inner String.
/// See [`String::into_boxed_str`]
Expand Down Expand Up @@ -222,7 +227,8 @@ mod tests {
fn calling_string_methods_works() {
let nes = NonEmptyString::new("string".to_owned()).unwrap();
// `len` is a `String` method.
assert!(nes.len() > 0);
assert_eq!(nes.len(), NonZero::new(6).unwrap());
assert!(nes.capacity() >= NonZero::new(6).unwrap());
}

#[test]
Expand Down