Skip to content

Commit a380485

Browse files
committed
improved documentation
1 parent 09ddeb9 commit a380485

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<a name="v2.0.1"></a>
2+
### v2.0.1 - 2021-05-20
3+
Improved documentation
4+
15
<a name="v2.0.0"></a>
26
### v2.0.0 - 2021-05-17
37
- regular expressions are now checked at compile time

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lazy-regex"
3-
version = "2.0.0"
3+
version = "2.0.1"
44
authors = ["Canop <[email protected]>"]
55
edition = "2018"
66
description = "lazy static regular expressions checked at compile time"
@@ -17,7 +17,7 @@ regex = "1.5"
1717
[dependencies.proc_macros]
1818
package = "lazy-regex-proc_macros"
1919
path = "src/proc_macros"
20-
version = "2.0.0"
20+
version = "2.0.1"
2121

2222
[workspace]
2323
members = ["src/proc_macros", "examples/regexes"]

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ assert_eq!(b, true);
7575
```rust
7676
use lazy_regex::regex_find;
7777

78-
let f_word = regex_find!(r#"\bf\w+\b"#, "The fox jumps.").unwrap();
79-
assert_eq!(f_word, "fox");
78+
let f_word = regex_find!(r#"\bf\w+\b"#, "The fox jumps.");
79+
assert_eq!(f_word, Some("fox"));
8080
```
8181

8282
# Capture
8383

8484
```rust
8585
use lazy_regex::regex_captures;
8686

87-
let (_, letter) = regex_captures!(r#"([a-z])\d+"#i, "form A42").unwrap();
87+
let (_, letter) = regex_captures!("([a-z])[0-9]+"i, "form A42").unwrap();
8888
assert_eq!(letter, "A");
8989

9090
let (whole, name, version) = regex_captures!(

src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Use the [regex!] macro to build regexes:
44
55
* they're checked at compile time
66
* they're wrapped in `once_cell` lazy static initializers so that they're compiled only once
7-
* they can hold flags with a familiar suffix syntax: `let case_insensitive_regex = regex!("ab*"i);`
7+
* they can hold flags as suffix: `let case_insensitive_regex = regex!("ab*"i);`
88
* regex creation is less verbose
99
10-
This macro builds normal instances of [regex::Regex] so all the usual features are available.
10+
This macro returns references to normal instances of [regex::Regex] so all the usual features are available.
1111
1212
You may also use shortcut macros for testing a match or capturing groups as substrings:
1313
@@ -58,16 +58,16 @@ assert_eq!(b, true);
5858
```
5959
use lazy_regex::regex_find;
6060
61-
let f_word = regex_find!(r#"\bf\w+\b"#, "The fox jumps.").unwrap();
62-
assert_eq!(f_word, "fox");
61+
let f_word = regex_find!(r#"\bf\w+\b"#, "The fox jumps.");
62+
assert_eq!(f_word, Some("fox"));
6363
```
6464
6565
# Capture
6666
6767
```
6868
use lazy_regex::regex_captures;
6969
70-
let (_, letter) = regex_captures!(r#"([a-z])\d+"#i, "form A42").unwrap();
70+
let (_, letter) = regex_captures!("([a-z])[0-9]+"i, "form A42").unwrap();
7171
assert_eq!(letter, "A");
7272
7373
let (whole, name, version) = regex_captures!(

src/proc_macros/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lazy-regex-proc_macros"
3-
version = "2.0.0"
3+
version = "2.0.1"
44
authors = ["Canop <[email protected]>"]
55
description = "proc macros for the lazy_regex crate"
66
license = "MIT"

src/proc_macros/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl From<LitStr> for RegexCode {
4141
};
4242
}
4343

44-
// the next line is here to prevent compilation if the
44+
// the next line prevents compilation if the
4545
// literal is invalid as a regular expression
4646
let regex = regex::Regex::new(&regex_string).unwrap();
4747

@@ -76,6 +76,9 @@ pub fn regex(input: TokenStream) -> TokenStream {
7676
RegexCode::from(lit_str).build.into()
7777
}
7878

79+
/// wrapping of the two arguments given to one of the
80+
/// `regex_is_match`, `regex_find`, or `regex_captures`
81+
/// macros.
7982
struct RegexAndExpr {
8083
regex_str: LitStr,
8184
value: Expr,
@@ -116,6 +119,14 @@ pub fn regex_is_match(input: TokenStream) -> TokenStream {
116119
q.into()
117120
}
118121

122+
/// extract the leftmost match of the regex in the
123+
/// second argument, as a &str
124+
///
125+
/// Example:
126+
/// ```
127+
/// let f_word = regex_find!(r#"\bf\w+\b"#, "The fox jumps.");
128+
/// assert_eq!(f_word, Some("fox"));
129+
/// ```
119130
#[proc_macro]
120131
pub fn regex_find(input: TokenStream) -> TokenStream {
121132
let regex_and_expr_args = parse_macro_input!(input as RegexAndExpr);

0 commit comments

Comments
 (0)