Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README example doesn't work #359

Closed
alexwlchan opened this issue May 8, 2017 · 0 comments
Closed

README example doesn't work #359

alexwlchan opened this issue May 8, 2017 · 0 comments

Comments

@alexwlchan
Copy link
Contributor

I took the first example from the README, and tried to run it with the current stable compiler:

$ rustc --version
rustc 1.17.0 (56124baa9 2017-04-24)

These are my files:

# Cargo.toml
[package]
name = "regex-example"
version = "0.1.0"
authors = ["Alex Chan <[email protected]>"]

[dependencies]
regex = "0.2"
// src/main.rs
extern crate 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 crate

error[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 crate

error[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 crate

error: aborting due to 3 previous errors

error: Could not compile `regex-example`.

To learn more, run the command again with --verbose.
rap2hpoutre added a commit to rap2hpoutre/regex that referenced this issue May 10, 2017
bors added a commit that referenced this issue May 10, 2017
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)
@bors bors closed this as completed in b9ac569 May 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant