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

the trait for<'r> FnMut<(&'r char,)> is not implemented for char #82863

Open
Tros-t opened this issue Mar 7, 2021 · 1 comment
Open

the trait for<'r> FnMut<(&'r char,)> is not implemented for char #82863

Tros-t opened this issue Mar 7, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Tros-t
Copy link

Tros-t commented Mar 7, 2021

I was aplitting a vector and when I tried to debug print it.
It resulted in an error:

My Code:

let splitted_vec = be.splitn(2, '-');
            for i in splitted_vec {
                println!("{:?}",i);
}

The error:

let splitted_vec = be.splitn(2, '-');
   |                                             ^^^ expected an `FnMut<(&char,)>` closure, found `char`
   |
   = help: the trait `for<'r> FnMut<(&'r char,)>` is not implemented for `char`


My program is the answer for advenofcode day two, and i am still working on it.
I want the program as simple as possible because I kind of have to present it to someone.

@jyn514
Copy link
Member

jyn514 commented Mar 7, 2021

MCVE:

fn main() {
    let be = vec!['a', 'b', 'c'];
    let splitted_vec = be.splitn(3, '-');
    for i in splitted_vec {
        println!("{:?}",i);
    }
}

Vec::split takes a closure, not a string: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.splitn. You probably want String::split instead: https://doc.rust-lang.org/std/string/struct.String.html#method.splitn.

@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants