File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -25,17 +25,24 @@ mod trait_impls;
25
25
#[ repr( transparent) ]
26
26
pub struct NonEmptyString ( String ) ;
27
27
28
- #[ allow( clippy:: len_without_is_empty) ] // is_empty would always returns false so it seems a bit silly to have it.
28
+ #[ allow( clippy:: len_without_is_empty, reason = " is_empty would always returns false so it seems a bit silly to have it." ) ]
29
29
impl NonEmptyString {
30
- /// Attempts to create a new NonEmptyString.
30
+ /// Attempts to create a new ` NonEmptyString` .
31
31
/// If the given `string` is empty, `Err` is returned, containing the original `String`, `Ok` otherwise.
32
- pub fn new ( string : String ) -> Result < NonEmptyString , String > {
32
+ pub fn new ( string : String ) -> Result < Self , String > {
33
33
if string. is_empty ( ) {
34
34
Err ( string)
35
35
} else {
36
36
Ok ( NonEmptyString ( string) )
37
37
}
38
38
}
39
+ /// Creates a new `NonEmptyString`, assuming it's not empty.
40
+ ///
41
+ /// # Safety
42
+ /// If the given `string` is empty, it'll be undefined behavior.
43
+ pub unsafe fn new_unchecked ( string : String ) -> Self {
44
+ Self :: new ( string) . unwrap_unchecked ( )
45
+ }
39
46
40
47
/// Returns a reference to the contained value.
41
48
pub fn get ( & self ) -> & str {
You can’t perform that action at this time.
0 commit comments