Skip to content

Commit ad4e6bf

Browse files
committed
implement NonEmptyString functions
1 parent 6368347 commit ad4e6bf

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/rule/non_empty/non_empty_string.rs

+53-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::refined::Refined;
22
use crate::result::Error;
3-
use crate::rule::NonEmptyRule;
3+
use crate::rule::{NonEmptyRule, NonEmptyVec};
44
use std::ops::Add;
55
use std::str::FromStr;
66

@@ -19,6 +19,58 @@ use std::str::FromStr;
1919
pub type NonEmptyString = Refined<NonEmptyStringRule>;
2020
pub type NonEmptyStringRule = NonEmptyRule<String>;
2121

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+
2274
impl FromStr for NonEmptyString {
2375
type Err = Error<String>;
2476
fn from_str(s: &str) -> Result<Self, Self::Err> {

0 commit comments

Comments
 (0)