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;
2525#[ repr( transparent) ]
2626pub struct NonEmptyString ( String ) ;
2727
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." ) ]
2929impl NonEmptyString {
30- /// Attempts to create a new NonEmptyString.
30+ /// Attempts to create a new ` NonEmptyString` .
3131 /// 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 > {
3333 if string. is_empty ( ) {
3434 Err ( string)
3535 } else {
3636 Ok ( NonEmptyString ( string) )
3737 }
3838 }
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+ }
3946
4047 /// Returns a reference to the contained value.
4148 pub fn get ( & self ) -> & str {
You can’t perform that action at this time.
0 commit comments