In programming language like java and c++ you can apply arithmetic operation like addition directly to the character data type
eg:
in java
char addition = 'a'+1;
System.out.println(addition);
in case of java character is consider as sub type of int
in c++
#include<iostream>
int main(){
char addition = 'a'+1;
std::cout << addition << std::endl;
return 0;
}
But when it come to rust*
fn main() {
let addition:char = 'a'+1;
println!("{}",addition);
}
output error
2 | let addition:char = 'a'+1;
| ---^- {integer}
| |
| char
"you need to convert to binary for incrementing, then convert back to char "
eg:
fn main() {
let addition:char = (b'a'+1) as char;
println!("{}",addition);
}
why in language like java and c++ we can simple increment character by adding 1 to it,but in rust it need to cover to bytes ,It it because of any safety reason rust compiler don't allow this or because of using"let" before the variable.
or
is it just because rust compiler don't automatically cover the data type instead of that we manually need to do it.
Can any one explain it clearly how this is working