File tree Expand file tree Collapse file tree 4 files changed +57
-1
lines changed Expand file tree Collapse file tree 4 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ Anchored search APIs are now available in `regex-automata 0.3`.
4040Add new ` Captures::extract ` method for easier capture group access.
4141* [ FEATURE #961 ] ( https://github.com/rust-lang/regex/issues/961 ) :
4242Add ` regex-lite ` crate with smaller binary sizes and faster compile times.
43+ * [ FEATURE #1022 ] ( https://github.com/rust-lang/regex/pull/1022 ) :
44+ Add ` TryFrom ` implementations for the ` Regex ` type.
4345
4446Performance improvements:
4547
Original file line number Diff line number Diff line change @@ -117,6 +117,24 @@ impl core::str::FromStr for Regex {
117117 }
118118}
119119
120+ impl TryFrom < & str > for Regex {
121+ type Error = Error ;
122+
123+ /// Attempts to parse a string into a regular expression
124+ fn try_from ( s : & str ) -> Result < Regex , Error > {
125+ Regex :: new ( s)
126+ }
127+ }
128+
129+ impl TryFrom < String > for Regex {
130+ type Error = Error ;
131+
132+ /// Attempts to parse a string into a regular expression
133+ fn try_from ( s : String ) -> Result < Regex , Error > {
134+ Regex :: new ( & s)
135+ }
136+ }
137+
120138/// Core regular expression methods.
121139impl Regex {
122140 /// Compiles a regular expression. Once compiled, it can be used repeatedly
Original file line number Diff line number Diff line change 1- use alloc:: { borrow:: Cow , sync:: Arc , vec:: Vec } ;
1+ use alloc:: { borrow:: Cow , string :: String , sync:: Arc , vec:: Vec } ;
22
33use regex_automata:: { meta, util:: captures, Input , PatternID } ;
44
@@ -124,6 +124,24 @@ impl core::str::FromStr for Regex {
124124 }
125125}
126126
127+ impl TryFrom < & str > for Regex {
128+ type Error = Error ;
129+
130+ /// Attempts to parse a string into a regular expression
131+ fn try_from ( s : & str ) -> Result < Regex , Error > {
132+ Regex :: new ( s)
133+ }
134+ }
135+
136+ impl TryFrom < String > for Regex {
137+ type Error = Error ;
138+
139+ /// Attempts to parse a string into a regular expression
140+ fn try_from ( s : String ) -> Result < Regex , Error > {
141+ Regex :: new ( & s)
142+ }
143+ }
144+
127145/// Core regular expression methods.
128146impl Regex {
129147 /// Compiles a regular expression. Once compiled, it can be used repeatedly
Original file line number Diff line number Diff line change @@ -126,6 +126,24 @@ impl core::str::FromStr for Regex {
126126 }
127127}
128128
129+ impl TryFrom < & str > for Regex {
130+ type Error = Error ;
131+
132+ /// Attempts to parse a string into a regular expression
133+ fn try_from ( s : & str ) -> Result < Regex , Error > {
134+ Regex :: new ( s)
135+ }
136+ }
137+
138+ impl TryFrom < String > for Regex {
139+ type Error = Error ;
140+
141+ /// Attempts to parse a string into a regular expression
142+ fn try_from ( s : String ) -> Result < Regex , Error > {
143+ Regex :: new ( & s)
144+ }
145+ }
146+
129147/// Core regular expression methods.
130148impl Regex {
131149 /// Compiles a regular expression. Once compiled, it can be used repeatedly
You can’t perform that action at this time.
0 commit comments