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]
pub fn new(t: T) -> Self
[src]
Wraps t
in an Unaligned
marker.
ⓘImportant traits for &'a mut Wpub fn of_ref(t: &T) -> &Self
[src]
Returns t
as if it were wrapped by Unaligned
.
This is safe because any &T
is a valid &Unaligned<T>
.
ⓘImportant traits for &'a mut Wpub fn of_mut(t: &mut T) -> &mut Self
[src]
Returns t
as if it were wrapped by Unaligned
.
This is safe because any &T
is a valid &Unaligned<T>
.
pub fn get(&self) -> T
[src]
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.
pub fn set(&mut self, t: T)
[src]
Replaces the contained value.
Trait Implementations
impl<T: LmdbRawIfUnaligned> Clone for Unaligned<T>
[src]
fn clone(&self) -> Self
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: LmdbRawIfUnaligned> Copy for Unaligned<T>
[src]
impl<T: LmdbRawIfUnaligned> LmdbRaw for Unaligned<T>
[src]
fn reported_type() -> String
[src]
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
[src]
Returns whether the default LMDB byte-by-byte comparison is correct for valid values of this type. Read more
fn ordered_as_integer() -> bool
[src]
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]
T: Binary,
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> Debug for Unaligned<T> where
T: Debug,
[src]
T: Debug,
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter. Read more
impl<T: LmdbRawIfUnaligned> Display for Unaligned<T> where
T: Display,
[src]
T: Display,
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter. Read more
impl<T: LmdbRawIfUnaligned> LowerExp for Unaligned<T> where
T: LowerExp,
[src]
T: LowerExp,
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> LowerHex for Unaligned<T> where
T: LowerHex,
[src]
T: LowerHex,
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> Octal for Unaligned<T> where
T: Octal,
[src]
T: Octal,
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> Pointer for Unaligned<T> where
T: Pointer,
[src]
T: Pointer,
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> UpperExp for Unaligned<T> where
T: UpperExp,
[src]
T: UpperExp,
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<T: LmdbRawIfUnaligned> UpperHex for Unaligned<T> where
T: UpperHex,
[src]
T: UpperHex,
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
[src]
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
[src]
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[src]
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>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Self) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Self) -> bool
[src]
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
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Self) -> bool
[src]
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
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl<T: LmdbRawIfUnaligned + Hash> Hash for Unaligned<T>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T: LmdbRawIfUnaligned + Add<T>> Add<Unaligned<T>> for Unaligned<T> where
T::Output: LmdbRawIfUnaligned,
[src]
T::Output: LmdbRawIfUnaligned,
type Output = Unaligned<T::Output>
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self::Output
[src]
Performs the +
operation.
impl<T: LmdbRawIfUnaligned + BitAnd<T>> BitAnd<Unaligned<T>> for Unaligned<T> where
T::Output: LmdbRawIfUnaligned,
[src]
T::Output: LmdbRawIfUnaligned,
type Output = Unaligned<T::Output>
The resulting type after applying the &
operator.
fn bitand(self, rhs: Self) -> Self::Output
[src]
Performs the &
operation.
impl<T: LmdbRawIfUnaligned + BitOr<T>> BitOr<Unaligned<T>> for Unaligned<T> where
T::Output: LmdbRawIfUnaligned,
[src]
T::Output: LmdbRawIfUnaligned,
type Output = Unaligned<T::Output>
The resulting type after applying the |
operator.
fn bitor(self, rhs: Self) -> Self::Output
[src]
Performs the |
operation.
impl<T: LmdbRawIfUnaligned + BitXor<T>> BitXor<Unaligned<T>> for Unaligned<T> where
T::Output: LmdbRawIfUnaligned,
[src]
T::Output: LmdbRawIfUnaligned,
type Output = Unaligned<T::Output>
The resulting type after applying the ^
operator.
fn bitxor(self, rhs: Self) -> Self::Output
[src]
Performs the ^
operation.
impl<T: LmdbRawIfUnaligned + Div<T>> Div<Unaligned<T>> for Unaligned<T> where
T::Output: LmdbRawIfUnaligned,
[src]
T::Output: LmdbRawIfUnaligned,
type Output = Unaligned<T::Output>
The resulting type after applying the /
operator.
fn div(self, rhs: Self) -> Self::Output
[src]
Performs the /
operation.
impl<T: LmdbRawIfUnaligned + Mul<T>> Mul<Unaligned<T>> for Unaligned<T> where
T::Output: LmdbRawIfUnaligned,
[src]
T::Output: LmdbRawIfUnaligned,
type Output = Unaligned<T::Output>
The resulting type after applying the *
operator.
fn mul(self, rhs: Self) -> Self::Output
[src]
Performs the *
operation.
impl<T: LmdbRawIfUnaligned + Rem<T>> Rem<Unaligned<T>> for Unaligned<T> where
T::Output: LmdbRawIfUnaligned,
[src]
T::Output: LmdbRawIfUnaligned,
type Output = Unaligned<T::Output>
The resulting type after applying the %
operator.
fn rem(self, rhs: Self) -> Self::Output
[src]
Performs the %
operation.
impl<T: LmdbRawIfUnaligned + Shl<T>> Shl<Unaligned<T>> for Unaligned<T> where
T::Output: LmdbRawIfUnaligned,
[src]
T::Output: LmdbRawIfUnaligned,
type Output = Unaligned<T::Output>
The resulting type after applying the <<
operator.
fn shl(self, rhs: Self) -> Self::Output
[src]
Performs the <<
operation.
impl<T: LmdbRawIfUnaligned + Shr<T>> Shr<Unaligned<T>> for Unaligned<T> where
T::Output: LmdbRawIfUnaligned,
[src]
T::Output: LmdbRawIfUnaligned,
type Output = Unaligned<T::Output>
The resulting type after applying the >>
operator.
fn shr(self, rhs: Self) -> Self::Output
[src]
Performs the >>
operation.
impl<T: LmdbRawIfUnaligned + Sub<T>> Sub<Unaligned<T>> for Unaligned<T> where
T::Output: LmdbRawIfUnaligned,
[src]
T::Output: LmdbRawIfUnaligned,
type Output = Unaligned<T::Output>
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Self::Output
[src]
Performs the -
operation.
impl<T: LmdbRawIfUnaligned + AddAssign<T>> AddAssign<Unaligned<T>> for Unaligned<T>
[src]
fn add_assign(&mut self, rhs: Self)
[src]
Performs the +=
operation.
impl<T: LmdbRawIfUnaligned + BitAndAssign<T>> BitAndAssign<Unaligned<T>> for Unaligned<T>
[src]
fn bitand_assign(&mut self, rhs: Self)
[src]
Performs the &=
operation.
impl<T: LmdbRawIfUnaligned + BitOrAssign<T>> BitOrAssign<Unaligned<T>> for Unaligned<T>
[src]
fn bitor_assign(&mut self, rhs: Self)
[src]
Performs the |=
operation.
impl<T: LmdbRawIfUnaligned + BitXorAssign<T>> BitXorAssign<Unaligned<T>> for Unaligned<T>
[src]
fn bitxor_assign(&mut self, rhs: Self)
[src]
Performs the ^=
operation.
impl<T: LmdbRawIfUnaligned + DivAssign<T>> DivAssign<Unaligned<T>> for Unaligned<T>
[src]
fn div_assign(&mut self, rhs: Self)
[src]
Performs the /=
operation.
impl<T: LmdbRawIfUnaligned + MulAssign<T>> MulAssign<Unaligned<T>> for Unaligned<T>
[src]
fn mul_assign(&mut self, rhs: Self)
[src]
Performs the *=
operation.
impl<T: LmdbRawIfUnaligned + RemAssign<T>> RemAssign<Unaligned<T>> for Unaligned<T>
[src]
fn rem_assign(&mut self, rhs: Self)
[src]
Performs the %=
operation.
impl<T: LmdbRawIfUnaligned + ShlAssign<T>> ShlAssign<Unaligned<T>> for Unaligned<T>
[src]
fn shl_assign(&mut self, rhs: Self)
[src]
Performs the <<=
operation.
impl<T: LmdbRawIfUnaligned + ShrAssign<T>> ShrAssign<Unaligned<T>> for Unaligned<T>
[src]
fn shr_assign(&mut self, rhs: Self)
[src]
Performs the >>=
operation.
impl<T: LmdbRawIfUnaligned + SubAssign<T>> SubAssign<Unaligned<T>> for Unaligned<T>
[src]
fn sub_assign(&mut self, rhs: Self)
[src]
Performs the -=
operation.