Skip to main content

buf_cmp

Function buf_cmp 

Source
pub fn buf_cmp<A: IntoBuf, B: IntoBuf>(a: A, b: B) -> Ordering
Expand description

Comparison operation on any two Buf values or values that convert to Buf.

Buf values are compared lexicographically by their byte values.

§Example

Rust’s standard string comparison approach also does byte-by-byte lexicographical comparison. Consequently, two &str values will always have the same relative ordering as their Buf equivalent.

use bufjson::{IntoBuf, buf_cmp};
use std::cmp::Ordering;

let a = "hello";
let b = "world";

assert!(a < b);
assert!(b > a);
assert!(buf_cmp(a, b) == Ordering::Less);
assert!(buf_cmp(b, a) == Ordering::Greater);