#[repr(packed(1))]pub struct Unaligned<T: LmdbRawIfUnaligned>(/* private fields */);
Expand description
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()
}
Implementations§
Source§impl<T: LmdbRawIfUnaligned> Unaligned<T>
impl<T: LmdbRawIfUnaligned> Unaligned<T>
Sourcepub fn of_ref(t: &T) -> &Self
pub 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>
.
Sourcepub fn of_mut(t: &mut T) -> &mut Self
pub 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>
.
Trait Implementations§
Source§impl<T: LmdbRawIfUnaligned + Add<T>> Add for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
impl<T: LmdbRawIfUnaligned + Add<T>> Add for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
Source§impl<T: LmdbRawIfUnaligned + AddAssign<T>> AddAssign for Unaligned<T>
impl<T: LmdbRawIfUnaligned + AddAssign<T>> AddAssign for Unaligned<T>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
operation. Read moreSource§impl<T: LmdbRawIfUnaligned + BitAnd<T>> BitAnd for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
impl<T: LmdbRawIfUnaligned + BitAnd<T>> BitAnd for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
Source§impl<T: LmdbRawIfUnaligned + BitAndAssign<T>> BitAndAssign for Unaligned<T>
impl<T: LmdbRawIfUnaligned + BitAndAssign<T>> BitAndAssign for Unaligned<T>
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
Performs the
&=
operation. Read moreSource§impl<T: LmdbRawIfUnaligned + BitOr<T>> BitOr for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
impl<T: LmdbRawIfUnaligned + BitOr<T>> BitOr for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
Source§impl<T: LmdbRawIfUnaligned + BitOrAssign<T>> BitOrAssign for Unaligned<T>
impl<T: LmdbRawIfUnaligned + BitOrAssign<T>> BitOrAssign for Unaligned<T>
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
Performs the
|=
operation. Read moreSource§impl<T: LmdbRawIfUnaligned + BitXor<T>> BitXor for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
impl<T: LmdbRawIfUnaligned + BitXor<T>> BitXor for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
Source§impl<T: LmdbRawIfUnaligned + BitXorAssign<T>> BitXorAssign for Unaligned<T>
impl<T: LmdbRawIfUnaligned + BitXorAssign<T>> BitXorAssign for Unaligned<T>
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
Performs the
^=
operation. Read moreSource§impl<T: LmdbRawIfUnaligned> Clone for Unaligned<T>
impl<T: LmdbRawIfUnaligned> Clone for Unaligned<T>
Source§impl<T: LmdbRawIfUnaligned + Div<T>> Div for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
impl<T: LmdbRawIfUnaligned + Div<T>> Div for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
Source§impl<T: LmdbRawIfUnaligned + DivAssign<T>> DivAssign for Unaligned<T>
impl<T: LmdbRawIfUnaligned + DivAssign<T>> DivAssign for Unaligned<T>
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Performs the
/=
operation. Read moreSource§impl<T: LmdbRawIfUnaligned + LmdbOrdKeyIfUnaligned> LmdbOrdKey for Unaligned<T>
impl<T: LmdbRawIfUnaligned + LmdbOrdKeyIfUnaligned> LmdbOrdKey for Unaligned<T>
Source§fn ordered_by_bytes() -> bool
fn ordered_by_bytes() -> bool
Returns whether the default LMDB byte-by-byte comparison is correct for
valid values of this type. Read more
Source§fn ordered_as_integer() -> bool
fn ordered_as_integer() -> bool
Returns whether LMDB will correctly handle this value with the
INTEGERKEY
or INTEGERDUP
flags. Read moreSource§impl<T: LmdbRawIfUnaligned> LmdbRaw for Unaligned<T>
impl<T: LmdbRawIfUnaligned> LmdbRaw for Unaligned<T>
Source§fn reported_type() -> String
fn reported_type() -> String
Returns the name of this type to report in error messages. Read more
Source§impl<T: LmdbRawIfUnaligned + Mul<T>> Mul for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
impl<T: LmdbRawIfUnaligned + Mul<T>> Mul for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
Source§impl<T: LmdbRawIfUnaligned + MulAssign<T>> MulAssign for Unaligned<T>
impl<T: LmdbRawIfUnaligned + MulAssign<T>> MulAssign for Unaligned<T>
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*=
operation. Read moreSource§impl<T: LmdbRawIfUnaligned + Ord> Ord for Unaligned<T>
impl<T: LmdbRawIfUnaligned + Ord> Ord for Unaligned<T>
Source§impl<T: LmdbRawIfUnaligned + PartialOrd<T>> PartialOrd for Unaligned<T>
impl<T: LmdbRawIfUnaligned + PartialOrd<T>> PartialOrd for Unaligned<T>
Source§impl<T: LmdbRawIfUnaligned + Rem<T>> Rem for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
impl<T: LmdbRawIfUnaligned + Rem<T>> Rem for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
Source§impl<T: LmdbRawIfUnaligned + RemAssign<T>> RemAssign for Unaligned<T>
impl<T: LmdbRawIfUnaligned + RemAssign<T>> RemAssign for Unaligned<T>
Source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
Performs the
%=
operation. Read moreSource§impl<T: LmdbRawIfUnaligned + Shl<T>> Shl for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
impl<T: LmdbRawIfUnaligned + Shl<T>> Shl for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
Source§impl<T: LmdbRawIfUnaligned + ShlAssign<T>> ShlAssign for Unaligned<T>
impl<T: LmdbRawIfUnaligned + ShlAssign<T>> ShlAssign for Unaligned<T>
Source§fn shl_assign(&mut self, rhs: Self)
fn shl_assign(&mut self, rhs: Self)
Performs the
<<=
operation. Read moreSource§impl<T: LmdbRawIfUnaligned + Shr<T>> Shr for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
impl<T: LmdbRawIfUnaligned + Shr<T>> Shr for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
Source§impl<T: LmdbRawIfUnaligned + ShrAssign<T>> ShrAssign for Unaligned<T>
impl<T: LmdbRawIfUnaligned + ShrAssign<T>> ShrAssign for Unaligned<T>
Source§fn shr_assign(&mut self, rhs: Self)
fn shr_assign(&mut self, rhs: Self)
Performs the
>>=
operation. Read moreSource§impl<T: LmdbRawIfUnaligned + Sub<T>> Sub for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
impl<T: LmdbRawIfUnaligned + Sub<T>> Sub for Unaligned<T>where
T::Output: LmdbRawIfUnaligned,
Source§impl<T: LmdbRawIfUnaligned + SubAssign<T>> SubAssign for Unaligned<T>
impl<T: LmdbRawIfUnaligned + SubAssign<T>> SubAssign for Unaligned<T>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-=
operation. Read moreimpl<T: LmdbRawIfUnaligned> Copy for Unaligned<T>
impl<T: LmdbRawIfUnaligned + Eq> Eq for Unaligned<T>
Auto Trait Implementations§
impl<T> Freeze for Unaligned<T>where
T: Freeze,
impl<T> RefUnwindSafe for Unaligned<T>where
T: RefUnwindSafe,
impl<T> Send for Unaligned<T>where
T: Send,
impl<T> Sync for Unaligned<T>where
T: Sync,
impl<T> Unpin for Unaligned<T>where
T: Unpin,
impl<T> UnwindSafe for Unaligned<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<V> AsLmdbBytes for Vwhere
V: LmdbRaw,
impl<V> AsLmdbBytes for Vwhere
V: LmdbRaw,
Source§fn as_lmdb_bytes(&self) -> &[u8] ⓘ
fn as_lmdb_bytes(&self) -> &[u8] ⓘ
Casts the given reference to a byte slice appropriate for storage
in LMDB.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'a, T> DefaultFeatures<'a> for T
impl<'a, T> DefaultFeatures<'a> for T
Source§fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a>>
fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a>>
Clone this value, and then immediately put it into a
Box
behind a trait object of this trait.Source§impl<V> FromLmdbBytes for Vwhere
V: LmdbRaw,
impl<V> FromLmdbBytes for Vwhere
V: LmdbRaw,
Source§impl<V> FromReservedLmdbBytes for Vwhere
V: LmdbRaw,
impl<V> FromReservedLmdbBytes for Vwhere
V: LmdbRaw,
Source§impl<T> LmdbOrdKeyIfUnaligned for Twhere
T: LmdbRaw + LmdbOrdKey,
impl<T> LmdbOrdKeyIfUnaligned for Twhere
T: LmdbRaw + LmdbOrdKey,
Source§fn ordered_by_bytes() -> bool
fn ordered_by_bytes() -> bool
Like
LmdbOrdKey::ordered_by_bytes()
Source§fn ordered_as_integer() -> bool
fn ordered_as_integer() -> bool
Like
LmdbOrdKey::ordered_as_integer()
Source§impl<T> LmdbRawIfUnaligned for Twhere
T: LmdbRaw,
impl<T> LmdbRawIfUnaligned for Twhere
T: LmdbRaw,
Source§fn reported_type() -> String
fn reported_type() -> String
Returns the name of this type to report in error messages. Read more
Source§impl<'a, T> NonSyncFeatures<'a> for Twhere
T: 'a + Clone,
impl<'a, T> NonSyncFeatures<'a> for Twhere
T: 'a + Clone,
Source§fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a>>
fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a>>
Clone this value, and then immediately put it into a
Box
behind a trait object of this trait.