From c79a2fc4ea9400e450323cfbe929b829bdc8ea61 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 29 Nov 2015 21:35:21 +0100 Subject: [PATCH] Examples and docs. --- src/nibbleslice.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/nibbleslice.rs b/src/nibbleslice.rs index 35068f0a2..e49244325 100644 --- a/src/nibbleslice.rs +++ b/src/nibbleslice.rs @@ -1,8 +1,29 @@ +//! Nibble-orientated view onto byte-slice, allowing nibble-precision offsets. use std::cmp::*; /// Nibble-orientated view onto byte-slice, allowing nibble-precision offsets. /// /// This is an immutable struct. No operations actually change it. +/// +/// # Example +/// ```rust +/// extern crate ethcore_util; +/// use ethcore_util::nibbleslice::*; +/// fn main() { +/// let d1 = &[0x01u8, 0x23, 0x45]; +/// let d2 = &[0x34u8, 0x50, 0x12]; +/// let d3 = &[0x00u8, 0x12]; +/// let n1 = NibbleSlice::new(d1); // 0,1,2,3,4,5 +/// let n2 = NibbleSlice::new(d2); // 3,4,5,0,1,2 +/// let n3 = NibbleSlice::new_offset(d3, 1); // 0,1,2 +/// assert!(n1 > n3); // 0,1,2,... > 0,1,2 +/// assert!(n1 < n2); // 0,... < 3,... +/// assert!(n2.mid(3) == n3); // 0,1,2 == 0,1,2 +/// assert!(n1.starts_with(&n3)); +/// assert_eq!(n1.common_prefix(&n3), 3); +/// assert_eq!(n2.mid(3).common_prefix(&n1), 3); +/// } +/// ``` #[derive(Debug, Copy, Clone, Eq, Ord)] pub struct NibbleSlice<'a> { data: &'a [u8],