You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// src/main.rsexterncrate regex;use regex::Regex;fn main(){let re = Regex::new(r"(?x)(?P<year>\d{4}) # the year-(?P<month>\d{2}) # the month-(?P<day>\d{2}) # the day").unwrap();let caps = re.captures("2010-03-14").unwrap();assert_eq!("2010", caps["year"]);assert_eq!("03", caps["month"]);assert_eq!("14", caps["day"]);
If I take these two files in a new project and run cargo run, I get an error:
$ cargo run Updating registry `https://github.com/rust-lang/crates.io-index` Downloading aho-corasick v0.6.3 Downloading libc v0.2.22 Compiling regex-syntax v0.4.0 Compiling void v1.0.2 Compiling libc v0.2.22 Compiling utf8-ranges v1.0.0 Compiling unreachable v0.1.1 Compiling thread-id v3.0.0 Compiling memchr v1.0.1 Compiling thread_local v0.3.3 Compiling aho-corasick v0.6.3 Compiling regex v0.2.1 Compiling regex-example v0.1.0 (file:///private/var/folders/0d/p_z4b6f90g1gc8h9y87w0td80000gn/T/tmp.l0If1jQ6/regex-example)error[E0277]: the trait bound `&str: std::cmp::PartialEq<str>` is not satisfied --> src/main.rs:15:5 |15 | assert_eq!("2010", caps["year"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::PartialEq<str>` is not implemented for `&str` | = help: the following implementations were found: <str as std::cmp::PartialEq> <str as std::cmp::PartialEq<std::ffi::OsString>> <str as std::cmp::PartialEq<std::ffi::OsStr>> <str as std::cmp::PartialEq<std::string::String>> and 3 others = note: this error originates in a macro outside of the current crateerror[E0277]: the trait bound `&str: std::cmp::PartialEq<str>` is not satisfied --> src/main.rs:16:5 |16 | assert_eq!("03", caps["month"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::PartialEq<str>` is not implemented for `&str` | = help: the following implementations were found: <str as std::cmp::PartialEq> <str as std::cmp::PartialEq<std::ffi::OsString>> <str as std::cmp::PartialEq<std::ffi::OsStr>> <str as std::cmp::PartialEq<std::string::String>> and 3 others = note: this error originates in a macro outside of the current crateerror[E0277]: the trait bound `&str: std::cmp::PartialEq<str>` is not satisfied --> src/main.rs:17:5 |17 | assert_eq!("14", caps["day"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::PartialEq<str>` is not implemented for `&str` | = help: the following implementations were found: <str as std::cmp::PartialEq> <str as std::cmp::PartialEq<std::ffi::OsString>> <str as std::cmp::PartialEq<std::ffi::OsStr>> <str as std::cmp::PartialEq<std::string::String>> and 3 others = note: this error originates in a macro outside of the current crateerror: aborting due to 3 previous errorserror: Could not compile `regex-example`.To learn more, run the command again with --verbose.
The text was updated successfully, but these errors were encountered:
Fix example in documentation
see #359
I choose to write:
```rust
assert_eq!("2010".to_string(), caps["year"]);
```
But I could have choose:
```rust
assert_eq!("2010", &caps["year"]);
```
Not sure which one is the best (maybe none of them)
I took the first example from the README, and tried to run it with the current stable compiler:
These are my files:
If I take these two files in a new project and run
cargo run
, I get an error:The text was updated successfully, but these errors were encountered: