Struct lmdb_zero::Unaligned
[−]
[src]
#[repr(packed)]pub struct Unaligned<T: LmdbRawIfUnaligned>(_);
Wrapper for arbitrary Copy
types which lifts their alignment
restrictions.
This allows using values which have non-byte alignment but are otherwise
LMDB-safe (as defined by LmdbRaw
) to be used with it. It obviously does
not make T
itself packed, so the same discussion with respect to padding
in the LmdbRaw
documentation applies here as well.
There is no way to get a reference to the contained value, as Rust currently has no way to express that the reference may be misaligned. (See also https://github.com/rust-lang/rust/issues/27060.)
Example
use lmdb_zero as lmdb; use lmdb_zero::Unaligned as U; fn get_a_u64(env: &lmdb::Environment, db: &lmdb::Database, key: &str) -> u64 { let tx = lmdb::ReadTransaction::new(env).unwrap(); let access = tx.access(); access.get::<str, U<u64>>(db, key).unwrap().get() }
Methods
impl<T: LmdbRawIfUnaligned> Unaligned<T>
[src]
fn new(t: T) -> Self
Wraps t
in an Unaligned
marker.
fn of_ref(t: &T) -> &Self
Returns t
as if it were wrapped by Unaligned
.
This is safe because any &T
is a valid &Unaligned<T>
.
fn of_mut(t: &mut T) -> &mut Self
Returns t
as if it were wrapped by Unaligned
.
This is safe because any &T
is a valid &Unaligned<T>
.
fn get(&self) -> T
Extracts the contained value.
This is safe as the compiler has visibility into the fact that the contained value is misaligned and can copy appropriately.
fn set(&mut self, t: T)
Replaces the contained value.
Trait Implementations
impl<T: Clone + LmdbRawIfUnaligned> Clone for Unaligned<T>
[src]
fn clone(&self) -> Unaligned<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: Copy + LmdbRawIfUnaligned> Copy for Unaligned<T>
[src]
impl<T: LmdbRawIfUnaligned> LmdbRaw for Unaligned<T>
[src]
fn reported_type() -> String
Returns the name of this type to report in error messages. Read more
impl<T: LmdbRawIfUnaligned + LmdbOrdKeyIfUnaligned> LmdbOrdKey for Unaligned<T>
[src]
fn ordered_by_bytes() -> bool
Returns whether the default LMDB byte-by-byte comparison is correct for valid values of this type. Read more
fn ordered_as_integer() -> bool
Returns whether LMDB will correctly handle this value with the INTEGERKEY
or INTEGERDUP
flags. Read more
impl<T: LmdbRawIfUnaligned> Binary for Unaligned<T> where T: Binary
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> Debug for Unaligned<T> where T: Debug
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> Display for Unaligned<T> where T: Display
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> LowerExp for Unaligned<T> where T: LowerExp
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> LowerHex for Unaligned<T> where T: LowerHex
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> Octal for Unaligned<T> where T: Octal
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> Pointer for Unaligned<T> where T: Pointer
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> UpperExp for Unaligned<T> where T: UpperExp
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> UpperHex for Unaligned<T> where T: UpperHex
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned + PartialEq<T>> PartialEq<Unaligned<T>> for Unaligned<T>
[src]
fn eq(&self, other: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl<T: LmdbRawIfUnaligned + Eq> Eq for Unaligned<T>
[src]
impl<T: LmdbRawIfUnaligned + PartialOrd<T>> PartialOrd<Unaligned<T>> for Unaligned<T>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Self) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Self) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Self) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Self) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<T: LmdbRawIfUnaligned + Ord> Ord for Unaligned<T>
[src]
fn cmp(&self, other: &Self) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl<T: LmdbRawIfUnaligned + Hash> Hash for Unaligned<T>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.
impl<T: LmdbRawIfUnaligned + Add<T>> Add<Unaligned<T>> for Unaligned<T> where T::Output: LmdbRawIfUnaligned
[src]
type Output = Unaligned<T::Output>
The resulting type after applying the +
operator
fn add(self, rhs: Self) -> Self::Output
The method for the +
operator
impl<T: LmdbRawIfUnaligned + BitAnd<T>> BitAnd<Unaligned<T>> for Unaligned<T> where T::Output: LmdbRawIfUnaligned
[src]
type Output = Unaligned<T::Output>
The resulting type after applying the &
operator
fn bitand(self, rhs: Self) -> Self::Output
The method for the &
operator
impl<T: LmdbRawIfUnaligned + BitOr<T>> BitOr<Unaligned<T>> for Unaligned<T> where T::Output: LmdbRawIfUnaligned
[src]
type Output = Unaligned<T::Output>
The resulting type after applying the |
operator
fn bitor(self, rhs: Self) -> Self::Output
The method for the |
operator
impl<T: LmdbRawIfUnaligned + BitXor<T>> BitXor<Unaligned<T>> for Unaligned<T> where T::Output: LmdbRawIfUnaligned
[src]
type Output = Unaligned<T::Output>
The resulting type after applying the ^
operator
fn bitxor(self, rhs: Self) -> Self::Output
The method for the ^
operator
impl<T: LmdbRawIfUnaligned + Div<T>> Div<Unaligned<T>> for Unaligned<T> where T::Output: LmdbRawIfUnaligned
[src]
type Output = Unaligned<T::Output>
The resulting type after applying the /
operator
fn div(self, rhs: Self) -> Self::Output
The method for the /
operator
impl<T: LmdbRawIfUnaligned + Mul<T>> Mul<Unaligned<T>> for Unaligned<T> where T::Output: LmdbRawIfUnaligned
[src]
type Output = Unaligned<T::Output>
The resulting type after applying the *
operator
fn mul(self, rhs: Self) -> Self::Output
The method for the *
operator
impl<T: LmdbRawIfUnaligned + Rem<T>> Rem<Unaligned<T>> for Unaligned<T> where T::Output: LmdbRawIfUnaligned
[src]
type Output = Unaligned<T::Output>
The resulting type after applying the %
operator
fn rem(self, rhs: Self) -> Self::Output
The method for the %
operator
impl<T: LmdbRawIfUnaligned + Shl<T>> Shl<Unaligned<T>> for Unaligned<T> where T::Output: LmdbRawIfUnaligned
[src]
type Output = Unaligned<T::Output>
The resulting type after applying the <<
operator
fn shl(self, rhs: Self) -> Self::Output
The method for the <<
operator
impl<T: LmdbRawIfUnaligned + Shr<T>> Shr<Unaligned<T>> for Unaligned<T> where T::Output: LmdbRawIfUnaligned
[src]
type Output = Unaligned<T::Output>
The resulting type after applying the >>
operator
fn shr(self, rhs: Self) -> Self::Output
The method for the >>
operator
impl<T: LmdbRawIfUnaligned + Sub<T>> Sub<Unaligned<T>> for Unaligned<T> where T::Output: LmdbRawIfUnaligned
[src]
type Output = Unaligned<T::Output>
The resulting type after applying the -
operator
fn sub(self, rhs: Self) -> Self::Output
The method for the -
operator
impl<T: LmdbRawIfUnaligned + AddAssign<T>> AddAssign<Unaligned<T>> for Unaligned<T>
[src]
fn add_assign(&mut self, rhs: Self)
The method for the +=
operator
impl<T: LmdbRawIfUnaligned + BitAndAssign<T>> BitAndAssign<Unaligned<T>> for Unaligned<T>
[src]
fn bitand_assign(&mut self, rhs: Self)
The method for the &=
operator
impl<T: LmdbRawIfUnaligned + BitOrAssign<T>> BitOrAssign<Unaligned<T>> for Unaligned<T>
[src]
fn bitor_assign(&mut self, rhs: Self)
The method for the |=
operator
impl<T: LmdbRawIfUnaligned + BitXorAssign<T>> BitXorAssign<Unaligned<T>> for Unaligned<T>
[src]
fn bitxor_assign(&mut self, rhs: Self)
The method for the ^=
operator
impl<T: LmdbRawIfUnaligned + DivAssign<T>> DivAssign<Unaligned<T>> for Unaligned<T>
[src]
fn div_assign(&mut self, rhs: Self)
The method for the /=
operator
impl<T: LmdbRawIfUnaligned + MulAssign<T>> MulAssign<Unaligned<T>> for Unaligned<T>
[src]
fn mul_assign(&mut self, rhs: Self)
The method for the *=
operator
impl<T: LmdbRawIfUnaligned + RemAssign<T>> RemAssign<Unaligned<T>> for Unaligned<T>
[src]
fn rem_assign(&mut self, rhs: Self)
The method for the %=
operator
impl<T: LmdbRawIfUnaligned + ShlAssign<T>> ShlAssign<Unaligned<T>> for Unaligned<T>
[src]
fn shl_assign(&mut self, rhs: Self)
The method for the <<=
operator
impl<T: LmdbRawIfUnaligned + ShrAssign<T>> ShrAssign<Unaligned<T>> for Unaligned<T>
[src]
fn shr_assign(&mut self, rhs: Self)
The method for the >>=
operator
impl<T: LmdbRawIfUnaligned + SubAssign<T>> SubAssign<Unaligned<T>> for Unaligned<T>
[src]
fn sub_assign(&mut self, rhs: Self)
The method for the -=
operator