#[macro_use]
pub mod deref_plus_impl_or_borrow_self;
#[macro_use]
pub mod tuple;
pub mod guarded_value;
pub mod wrap;
pub fn to_key_prefix_iter_upper_bound(key_prefix: &[u8]) -> Option<Vec<u8>> {
    let mut upper_bound_excl_value = key_prefix.to_vec();
    if upper_bound_excl_value.len() == 0 {
        None
    } else {
        let mut carry = 1;
        let len = upper_bound_excl_value.len();
        for i in 0..len {
            if upper_bound_excl_value[len - 1 - i] == 255 {
                upper_bound_excl_value[len - 1 - i] = 0;
            } else {
                upper_bound_excl_value[len - 1 - i] += 1;
                carry = 0;
                break;
            }
        }
        if carry == 1 {
            None
        } else {
            Some(upper_bound_excl_value)
        }
    }
}
pub mod access_mode {
    pub trait AccessMode {
        const READ_ONLY: bool;
    }
    pub struct Read;
    pub struct Write;
    impl AccessMode for Read {
        const READ_ONLY: bool = true;
    }
    impl AccessMode for Write {
        const READ_ONLY: bool = false;
    }
}
pub trait WrappedCreateFrom<FromType, ToType> {
    fn take(x: FromType) -> ToType;
    fn take_from(dest: &mut ToType, x: FromType) { *dest = Self::take(x); }
}
impl<'x, T: Clone> WrappedCreateFrom<&'x T, UnsafeCell<T>> for UnsafeCell<T> {
    fn take(val: &'x T) -> UnsafeCell<T> { UnsafeCell::new(val.clone()) }
    fn take_from(dest: &mut UnsafeCell<T>, x: &'x T) {
        dest.get_mut().clone_from(x);
    }
}
pub trait UnsafeCellExtension<T: Sized> {
    fn get_ref(&self) -> &T;
    fn get_mut(&mut self) -> &mut T;
    unsafe fn get_as_mut(&self) -> &mut T;
}
impl<T: Sized> UnsafeCellExtension<T> for UnsafeCell<T> {
    fn get_ref(&self) -> &T { unsafe { &*self.get() } }
    fn get_mut(&mut self) -> &mut T { unsafe { &mut *self.get() } }
    unsafe fn get_as_mut(&self) -> &mut T { &mut *self.get() }
}
pub trait StateRootWithAuxInfoToFromRlpBytes {
    fn to_rlp_bytes(&self) -> Vec<u8>;
    fn from_rlp_bytes(bytes: &[u8]) -> Result<StateRootWithAuxInfo>;
}
impl StateRootWithAuxInfoToFromRlpBytes for StateRootWithAuxInfo {
    fn to_rlp_bytes(&self) -> Vec<u8> { self.rlp_bytes() }
    fn from_rlp_bytes(bytes: &[u8]) -> Result<Self> {
        Ok(Self::decode(&Rlp::new(bytes))?)
    }
}
use crate::Result;
use cfx_internal_common::StateRootWithAuxInfo;
use rlp::{Decodable, Encodable, Rlp};
use std::cell::UnsafeCell;