Skip to main content

is_empty_range

Function is_empty_range 

Source
pub fn is_empty_range(start: &Bound<&[u8]>, end: &Bound<&[u8]>) -> bool
Expand description

Whether a range is empty solely from its bounds.

Every KvStore backend must normalize these ranges to an empty result before calling an engine whose native range API rejects them. A range is empty when both bounds are keyed and the start sorts after the end, or when equal keyed bounds exclude that one possible key.

use std::ops::Bound;

use fasm_storage::is_empty_range;

assert!(is_empty_range(
    &Bound::Included(b"z"),
    &Bound::Excluded(b"a"),
));
assert!(is_empty_range(
    &Bound::Excluded(b"k"),
    &Bound::Included(b"k"),
));
assert!(!is_empty_range(
    &Bound::Included(b"k"),
    &Bound::Included(b"k"),
));