Examples and docs.
This commit is contained in:
parent
930865fefb
commit
c79a2fc4ea
@ -1,8 +1,29 @@
|
|||||||
|
//! Nibble-orientated view onto byte-slice, allowing nibble-precision offsets.
|
||||||
use std::cmp::*;
|
use std::cmp::*;
|
||||||
|
|
||||||
/// Nibble-orientated view onto byte-slice, allowing nibble-precision offsets.
|
/// Nibble-orientated view onto byte-slice, allowing nibble-precision offsets.
|
||||||
///
|
///
|
||||||
/// This is an immutable struct. No operations actually change it.
|
/// 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)]
|
#[derive(Debug, Copy, Clone, Eq, Ord)]
|
||||||
pub struct NibbleSlice<'a> {
|
pub struct NibbleSlice<'a> {
|
||||||
data: &'a [u8],
|
data: &'a [u8],
|
||||||
|
Loading…
Reference in New Issue
Block a user