The trait `FnMut<(char,)>` is not implemented for `String` when trying to split a string

前端 未结 2 696
[愿得一人]
[愿得一人] 2020-11-29 12:59

I need to split a String (not &str) by another String:

use std::str::Split;

fn main() {
    let x = \"\".to_strin         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 13:18

    All is in the documentation. You can provide one of:

    • A &str,
    • A char,
    • A closure,

    Those three types implement the Pattern trait. You are giving a String to split instead of a &str.

    Example:

    fn main() {
        let x = "".to_string();
        let split = x.split("");
    }
    

提交回复
热议问题