I'm new to rust. trying solve some simple problems and ran into something.
use std::io;
use std::cmp::Ordering;
fn main(){
let mut in1=String::new();
io::stdin()
.read_line(&mut in1).unwrap(); //a number specifying he number of elements in the input eg 6
let in1:i32=in1.trim().parse().unwrap();
let in1 = in1/2;
let mut in2= String::new();
io::stdin()
.read_line(&mut in2).unwrap(); //input of an array in the format number number number etc. rg : 233 456 665 8239 361 0912
let mut i=1;
let mut fwd=String::new();
for element in in2.split(' '){
fwd.push_str(
match i.cmp(&in1){
// Ordering::Greater=>&element.rev()[..1], //supposed to be the least significant digit of the number
Ordering::Greater=>
&element[..1],
_ =>
&element[..1], //most significant digit of the number
}
);
i+=1;
}
println!("{}",fwd);
/* ^^ number having most significant digits of the first half of the input and least significant digits of the second half
by the example this number should be 246912*/
}
when i tried to rev() on the iterating element i'm getting this error
error[E0599]: the method `rev` exists for reference `&str`, but its trait bounds were not satisfied
--> src\main.rs:19:45
|
19 | Ordering::Greater=>&element.rev()[..1],
| ^^^ method cannot be called on `&str` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`&str: Iterator`
which is required by `&mut &str: Iterator`
`str: Iterator`
which is required by `&mut str: Iterator`
For more information about this error, try `rustc --explain E0599`.
i tried to figure it out but idk why it's not working so please help