@@ -14,8 +14,8 @@ pub struct Ing {
14
14
}
15
15
16
16
impl Ing {
17
- pub fn new ( pat : String ) -> Ing {
18
- Ing { pat }
17
+ pub const fn new ( pat : String ) -> Self {
18
+ Self { pat }
19
19
}
20
20
}
21
21
@@ -48,14 +48,14 @@ impl TryFrom<usize> for IngSendFrom {
48
48
49
49
fn try_from ( value : usize ) -> Result < Self , Self :: Error > {
50
50
match value {
51
- 0 => IngSendFrom :: None ,
52
- 1 => IngSendFrom :: Ms ,
53
- 2 => IngSendFrom :: GTalk ,
54
- 3 => IngSendFrom :: Qq ,
55
- 5 => IngSendFrom :: Sms ,
56
- 6 => IngSendFrom :: CellPhone ,
57
- 8 => IngSendFrom :: Web ,
58
- 9 => IngSendFrom :: Code ,
51
+ 0 => Self :: None ,
52
+ 1 => Self :: Ms ,
53
+ 2 => Self :: GTalk ,
54
+ 3 => Self :: Qq ,
55
+ 5 => Self :: Sms ,
56
+ 6 => Self :: CellPhone ,
57
+ 8 => Self :: Web ,
58
+ 9 => Self :: Code ,
59
59
u => bail ! ( "Unknown value of ing source: {}" , u) ,
60
60
}
61
61
. into_ok ( )
@@ -76,12 +76,13 @@ pub fn fmt_content(content: &str) -> String {
76
76
static ref REGEX : Regex =
77
77
Regex :: new( r#"<a.*href="https://home.cnblogs.com/u/.*?".*>(@.*?)</a>"# ) . unwrap( ) ;
78
78
}
79
- if let Some ( caps) = REGEX . captures ( content) {
80
- let at_user = caps. get ( 1 ) . unwrap ( ) . as_str ( ) ;
81
- REGEX . replace ( content, at_user) . to_string ( )
82
- } else {
83
- content. to_string ( )
84
- }
79
+ REGEX . captures ( content) . map_or_else (
80
+ || content. to_string ( ) ,
81
+ |caps| {
82
+ let at_user = caps. get ( 1 ) . unwrap ( ) . as_str ( ) ;
83
+ REGEX . replace ( content, at_user) . to_string ( )
84
+ } ,
85
+ )
85
86
}
86
87
87
88
pub fn rm_ing_at_user_tag ( text : & str ) -> String {
@@ -97,9 +98,8 @@ pub fn get_ing_at_user_tag_text(text: &str) -> String {
97
98
static ref REGEX : Regex =
98
99
Regex :: new( r#"<a.*href="https://home.cnblogs.com/u/.*?".*>@(.*?)</a>:"# ) . unwrap( ) ;
99
100
}
100
- if let Some ( caps) = REGEX . captures ( text) {
101
- caps. get ( 1 ) . unwrap ( ) . as_str ( ) . to_string ( )
102
- } else {
103
- "" . to_string ( )
104
- }
101
+ REGEX . captures ( text) . map_or_else (
102
+ || "" . to_string ( ) ,
103
+ |caps| caps. get ( 1 ) . unwrap ( ) . as_str ( ) . to_string ( ) ,
104
+ )
105
105
}
0 commit comments