1
1
use crate :: refined:: Refined ;
2
2
use crate :: result:: Error ;
3
- use crate :: rule:: NonEmptyRule ;
3
+ use crate :: rule:: { NonEmptyRule , NonEmptyVec } ;
4
4
use std:: ops:: Add ;
5
5
use std:: str:: FromStr ;
6
6
@@ -19,6 +19,58 @@ use std::str::FromStr;
19
19
pub type NonEmptyString = Refined < NonEmptyStringRule > ;
20
20
pub type NonEmptyStringRule = NonEmptyRule < String > ;
21
21
22
+ impl NonEmptyString {
23
+ pub fn insert ( self , idx : usize , ch : char ) -> Self {
24
+ let mut result = self . into_value ( ) ;
25
+ result. insert ( idx, ch) ;
26
+ NonEmptyString :: unsafe_new ( result)
27
+ }
28
+
29
+ pub fn push ( self , ch : char ) -> Self {
30
+ let mut result = self . into_value ( ) ;
31
+ result. push ( ch) ;
32
+ NonEmptyString :: unsafe_new ( result)
33
+ }
34
+
35
+ pub fn push_str ( self , string : & str ) -> Self {
36
+ let mut result = self . into_value ( ) ;
37
+ result. push_str ( string) ;
38
+ NonEmptyString :: unsafe_new ( result)
39
+ }
40
+
41
+ pub fn as_bytes ( & self ) -> NonEmptyVec < u8 > {
42
+ NonEmptyVec :: unsafe_new ( self . value ( ) . as_bytes ( ) . to_vec ( ) )
43
+ }
44
+
45
+ pub fn repeat ( & self , n : usize ) -> Self {
46
+ NonEmptyString :: unsafe_new ( self . value ( ) . repeat ( n) )
47
+ }
48
+
49
+ pub fn to_ascii_lowercase ( & self ) -> Self {
50
+ NonEmptyString :: unsafe_new ( self . value ( ) . to_ascii_lowercase ( ) )
51
+ }
52
+
53
+ pub fn to_lowercase ( & self ) -> Self {
54
+ NonEmptyString :: unsafe_new ( self . value ( ) . to_lowercase ( ) )
55
+ }
56
+
57
+ pub fn to_ascii_uppercase ( & self ) -> Self {
58
+ NonEmptyString :: unsafe_new ( self . value ( ) . to_ascii_uppercase ( ) )
59
+ }
60
+
61
+ pub fn to_uppercase ( & self ) -> Self {
62
+ NonEmptyString :: unsafe_new ( self . value ( ) . to_uppercase ( ) )
63
+ }
64
+
65
+ pub fn capacity ( & self ) -> usize {
66
+ self . value ( ) . capacity ( )
67
+ }
68
+
69
+ pub fn len ( & self ) -> usize {
70
+ self . value ( ) . len ( )
71
+ }
72
+ }
73
+
22
74
impl FromStr for NonEmptyString {
23
75
type Err = Error < String > ;
24
76
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
0 commit comments