Error "mismatched types
expected &str
, found slice [&str]
rustc(E0308)
main.rs(191, 25): expected &str
, found slice [&str]
"
for example
let a= vec!["d","dd","jds"];
let aa = a[1..3];
let vv = parse_pair(aa,',');
//below func def
also Error:
"mismatched types
expected str
, found slice
note: expected reference &str
found reference &[std::string::String]
rustc(E0308)
main.rs(189, 25): expected str
, found slice"
(from one vector):init now is Vec
let v = &init[2..3]; //From book_
fn parse_pair<T: FromStr>(s : &str, separator :char) -> Option<(T,T)>{
match s.find(separator){
None => None,
Some(index) => {
match (T::from_str(&s[..index]), T::from_str(&s[index+1..])){
(Ok(l),Ok(r)) => Some((l, r)),
_ => None
}
}
}}
2I have vector with smth,want to unpack him convinient but can't imagine how(al names only from structure,not important)
write!(&mut file, "equation_type:{data1} {sep} \n
add_arg:{data2} {sep} \n
margin_domain:{data3:?} {sep} \n
time_eval_period_stage:{data4} {sep} \n
bound_type:{data5} {sep} \n
init_conditions:{data6:?} {sep} \n
quantity_split_nodes:{data7} {sep} \n
n_corant:{data8} \n",data1 = init[0], data2 = init[1] , data3 = init[2],//parse_pair(&init[3],","),
data4 = init[4], data5 = init[5], data6 =init[6],// parse_three(String::as_str(String::from(init[7])),","),
data7 = init[8],
data8 = init[9],sep = sgn).unwrap();
3
let mut init: Vec<String> =
//.......contents.split("\n").map(|x| x.trim()).map(str::to_string).collect();
//where content it is text in file
let new_init: &mut Vec<String> = &mut init;
for x in new_init{
println!("{:?}",x.retain(|c| c==','));
/*let y = x.retain(|c| c !=',').as_str();
init[0].push_str(y);*/
}
This print () always,what's wrong?)