strcmp() returns an integer indicating the result of the comparison, as follows:
0, if the s1 and s2 are equal;
a negative value if s1 is less than s2;
a positive value if s1 is greater than s2.
So basically, if C had higher level constructs, it would be identical to Rust here.
So, even if it is cool to manipulate strings by using addition/subtraction, it is still bad language design and very unintuitive.
Rust has implAdd<&str> forString and implAddAssign<&str> forString. Both append as expected.
But maybe you meant numeric addition specifically.
In that case, yes, Rust doesn’t have that, although it’s an impl<'a> Step for &'astr away from having something similar (it would be ("AAAAA"..).next()).
implStepforchar already exists of course, but shouldn’t if we take your argument to its logical conclusion.
Oh, and C would most definitely have this feature if it could. Numerical manipulation of chars is commonplace there.
The general theme of your comment is good, but the example is…
// rust eprintln!("{}", "AAAAB" > "AAAAA") // true eprintln!("{}", "Mark" > "John") // true
// C printf("%d\n", strcmp("AAAAB", "AAAAA")); // 1 printf("%d\n", strcmp("Mark", "John")); // 1
strcmp()
docs:So basically, if C had higher level constructs, it would be identical to Rust here.
Rust has
impl Add<&str> for String
andimpl AddAssign<&str> for String
. Both append as expected.But maybe you meant numeric addition specifically.
In that case, yes, Rust doesn’t have that, although it’s an
impl<'a> Step for &'a str
away from having something similar (it would be("AAAAA"..).next()
).impl Step for char
already exists of course, but shouldn’t if we take your argument to its logical conclusion.Oh, and C would most definitely have this feature if it could. Numerical manipulation of
char
s is commonplace there.