-
| Hi! Currently I'm the first example of this example section out: use regex::bytes::Regex;
fn main() {
    let re = Regex::new(r"arch").unwrap();
    re.replace("I use arch btw", "windows");
}but I'm getting the following output from  error[E0277]: expected a `Fn<(®ex::bytes::Captures<'_>,)>` closure, found `str`
   --> src/main.rs:5:34
    |
5   |     re.replace("I use arch btw", "windows");
    |        -------                   ^^^^^^^^^ expected an `Fn<(®ex::bytes::Captures<'_>,)>` closure, found `str`
    |        |
    |        required by a bound introduced by this call
    |
    = help: the trait `for<'r, 's> Fn<(&'r regex::bytes::Captures<'s>,)>` is not implemented for `str`
    = help: the following other types implement trait `regex::bytes::Replacer`:
              &'a Cow<'a, [u8]>
              &'a Vec<u8>
              &'a [u8]
              Cow<'a, [u8]>
              Vec<u8>
              regex::bytes::NoExpand<'t>
              regex::bytes::ReplacerRef<'a, R>
    = note: required because of the requirements on the impl of `for<'r, 's> FnOnce<(&'r regex::bytes::Captures<'s>,)>` for `&str`
    = note: required because of the requirements on the impl of `regex::bytes::Replacer` for `&str`
note: required by a bound in `regex::bytes::Regex::replace`
   --> /home/tornax/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-1.6.0/src/re_bytes.rs:457:27
    |
457 |     pub fn replace<'t, R: Replacer>(
    |                           ^^^^^^^^ required by this bound in `regex::bytes::Regex::replace`
error[E0308]: mismatched types
   --> src/main.rs:5:16
    |
5   |     re.replace("I use arch btw", "windows");
    |        ------- ^^^^^^^^^^^^^^^^ expected slice `[u8]`, found `str`
    |        |
    |        arguments to this function are incorrect
    |
    = note: expected reference `&[u8]`
               found reference `&'static str`
note: associated function defined here
   --> /home/tornax/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-1.6.0/src/re_bytes.rs:457:12
    |
457 |     pub fn replace<'t, R: Replacer>(
    |            ^^^^^^^
help: consider adding a leading `b`
    |
5   |     re.replace(b"I use arch btw", "windows");
    |                +
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `rust_tmp` due to 2 previous errorsThis is my  [package]
name = "rust_tmp"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
regex = "1.6.0"what am I doing wrong? | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            TornaxO7
          
      
      
        Oct 16, 2022 
      
    
    Replies: 1 comment 1 reply
-
| Eh, I just looked back to my code and saw this:  | 
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
      Answer selected by
        TornaxO7
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Eh, I just looked back to my code and saw this:
use regex::bytes::Regexwhich looks like that the regex should be used on bytes.... which is true, after changing it toregex::Regexeverything works again.