From 19e35bc81058c8dbb2daaa0818832b51fbe204c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Fern=C3=A1ndez=20Serrata?= <76864299+Rudxain@users.noreply.github.com> Date: Fri, 11 Oct 2024 03:07:23 -0400 Subject: [PATCH 1/4] define `new_unchecked` --- src/lib.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 61fe38e..564154d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,17 +25,24 @@ mod trait_impls; #[repr(transparent)] pub struct NonEmptyString(String); -#[allow(clippy::len_without_is_empty)] // is_empty would always returns false so it seems a bit silly to have it. +#[allow(clippy::len_without_is_empty, reason = "is_empty would always returns false so it seems a bit silly to have it.")] impl NonEmptyString { - /// Attempts to create a new NonEmptyString. + /// Attempts to create a new `NonEmptyString`. /// If the given `string` is empty, `Err` is returned, containing the original `String`, `Ok` otherwise. - pub fn new(string: String) -> Result { + pub fn new(string: String) -> Result { if string.is_empty() { Err(string) } else { Ok(NonEmptyString(string)) } } + /// Creates a new `NonEmptyString`, assuming it's not empty. + /// + /// # Safety + /// If the given `string` is empty, it'll be undefined behavior. + pub unsafe fn new_unchecked(string: String) -> Self { + Self::new(string).unwrap_unchecked() + } /// Returns a reference to the contained value. pub fn get(&self) -> &str { From cd411e23aeabb1487b81b52444b1a483a937bde4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Fern=C3=A1ndez=20Serrata?= <76864299+Rudxain@users.noreply.github.com> Date: Fri, 11 Oct 2024 03:10:23 -0400 Subject: [PATCH 2/4] increment minor version in `Cargo.toml` --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c269606..3c32ab9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "non-empty-string" -version = "0.2.4" +version = "0.3.0" edition = "2021" authors = ["Midas Lambrichts "] license = "MIT OR Apache-2.0" From bd59af5e2efb63b48491120e8898f344fd853908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Fern=C3=A1ndez=20Serrata?= <76864299+Rudxain@users.noreply.github.com> Date: Fri, 11 Oct 2024 22:11:11 -0400 Subject: [PATCH 3/4] bump patch rather than minor version https://github.com/MidasLamb/non-empty-string/pull/17#discussion_r1796750844 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3c32ab9..69261d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "non-empty-string" -version = "0.3.0" +version = "0.2.5" edition = "2021" authors = ["Midas Lambrichts "] license = "MIT OR Apache-2.0" From cc674abbd136a8f4a12c41673c2b32fbd6d510e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Fern=C3=A1ndez=20Serrata?= <76864299+Rudxain@users.noreply.github.com> Date: Fri, 11 Oct 2024 22:14:30 -0400 Subject: [PATCH 4/4] disambiguate doc of `new_unchecked` --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 564154d..915ab88 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,7 @@ impl NonEmptyString { Ok(NonEmptyString(string)) } } - /// Creates a new `NonEmptyString`, assuming it's not empty. + /// Creates a new `NonEmptyString`, assuming `string` is not empty. /// /// # Safety /// If the given `string` is empty, it'll be undefined behavior.