pub struct KeyRange { /* private fields */ }Expand description
An inclusive range of u64 keys, [start, end].
Construct one with new (which rejects start > end) or
point for a single key. Two ranges held by different
transactions conflict only when they overlap and
their lock modes are incompatible.
§Examples
use lock_db::KeyRange;
let r = KeyRange::new(100, 200).unwrap();
assert!(r.contains(150));
assert!(!r.contains(201));
assert!(r.overlaps(KeyRange::point(200)));
assert!(!r.overlaps(KeyRange::new(201, 300).unwrap()));
// An inverted range is rejected.
assert!(KeyRange::new(5, 4).is_none());Implementations§
Source§impl KeyRange
impl KeyRange
Sourcepub const fn new(start: u64, end: u64) -> Option<Self>
pub const fn new(start: u64, end: u64) -> Option<Self>
Creates the inclusive range [start, end], or None if start > end.
§Examples
use lock_db::KeyRange;
assert!(KeyRange::new(0, 0).is_some()); // a single key
assert!(KeyRange::new(1, 9).is_some());
assert!(KeyRange::new(9, 1).is_none());Sourcepub const fn point(key: u64) -> Self
pub const fn point(key: u64) -> Self
Creates a range covering the single key key.
§Examples
use lock_db::KeyRange;
let k = KeyRange::point(42);
assert_eq!(k.start(), 42);
assert_eq!(k.end(), 42);Sourcepub const fn contains(self, key: u64) -> bool
pub const fn contains(self, key: u64) -> bool
Returns true if key falls within the range.
§Examples
use lock_db::KeyRange;
let r = KeyRange::new(10, 20).unwrap();
assert!(r.contains(10) && r.contains(20));
assert!(!r.contains(9) && !r.contains(21));Sourcepub const fn overlaps(self, other: KeyRange) -> bool
pub const fn overlaps(self, other: KeyRange) -> bool
Returns true if the two ranges share at least one key.
Overlap is symmetric: a.overlaps(b) == b.overlaps(a).
§Examples
use lock_db::KeyRange;
let a = KeyRange::new(10, 20).unwrap();
assert!(a.overlaps(KeyRange::new(20, 30).unwrap())); // touch at 20
assert!(!a.overlaps(KeyRange::new(21, 30).unwrap()));Trait Implementations§
impl Copy for KeyRange
Source§impl<'de> Deserialize<'de> for KeyRange
impl<'de> Deserialize<'de> for KeyRange
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for KeyRange
impl StructuralPartialEq for KeyRange
Auto Trait Implementations§
impl Freeze for KeyRange
impl RefUnwindSafe for KeyRange
impl Send for KeyRange
impl Sync for KeyRange
impl Unpin for KeyRange
impl UnsafeUnpin for KeyRange
impl UnwindSafe for KeyRange
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more