Compare

Function Compare 

Source
pub fn Compare(a: impl AsRef<[byte]>, b: impl AsRef<[byte]>) -> int
Expand description

Compare returns an integer comparing two byte slices lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

zh-cn Compare函数返回一个整数表示两个&[byte]切片按字典序比较的结果(类同C的strcmp)。如果a == b返回0;如果a < b返回-1;否则返回+1。

§Example

use gostd_bytes as bytes;

   assert_eq!(-1, bytes::Compare(&[b'a'], &[b'b']));
   assert_eq!(0, bytes::Compare(b"a", [b'a']));
   assert_eq!(1, bytes::Compare(b"b", b"a"));