Struct Unaligned

Source
#[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>

Source

pub fn new(t: T) -> Self

Wraps t in an Unaligned marker.

Source

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>.

Source

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>.

Source

pub 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.

Source

pub fn set(&mut self, t: T)

Replaces the contained value.

Trait Implementations§

Source§

impl<T: LmdbRawIfUnaligned + Add<T>> Add for Unaligned<T>

Source§

type Output = Unaligned<<T as Add>::Output>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + AddAssign<T>> AddAssign for Unaligned<T>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T> Binary for Unaligned<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T: LmdbRawIfUnaligned + BitAnd<T>> BitAnd for Unaligned<T>

Source§

type Output = Unaligned<<T as BitAnd>::Output>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + BitAndAssign<T>> BitAndAssign for Unaligned<T>

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + BitOr<T>> BitOr for Unaligned<T>

Source§

type Output = Unaligned<<T as BitOr>::Output>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + BitOrAssign<T>> BitOrAssign for Unaligned<T>

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + BitXor<T>> BitXor for Unaligned<T>

Source§

type Output = Unaligned<<T as BitXor>::Output>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + BitXorAssign<T>> BitXorAssign for Unaligned<T>

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl<T: LmdbRawIfUnaligned> Clone for Unaligned<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Unaligned<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Display for Unaligned<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T: LmdbRawIfUnaligned + Div<T>> Div for Unaligned<T>

Source§

type Output = Unaligned<<T as Div>::Output>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + DivAssign<T>> DivAssign for Unaligned<T>

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + Hash> Hash for Unaligned<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: LmdbRawIfUnaligned + LmdbOrdKeyIfUnaligned> LmdbOrdKey for Unaligned<T>

Source§

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

Returns whether LMDB will correctly handle this value with the INTEGERKEY or INTEGERDUP flags. Read more
Source§

impl<T: LmdbRawIfUnaligned> LmdbRaw for Unaligned<T>

Source§

fn reported_type() -> String

Returns the name of this type to report in error messages. Read more
Source§

impl<T> LowerExp for Unaligned<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> LowerHex for Unaligned<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T: LmdbRawIfUnaligned + Mul<T>> Mul for Unaligned<T>

Source§

type Output = Unaligned<<T as Mul>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + MulAssign<T>> MulAssign for Unaligned<T>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<T> Octal for Unaligned<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T: LmdbRawIfUnaligned + Ord> Ord for Unaligned<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: LmdbRawIfUnaligned + PartialEq<T>> PartialEq for Unaligned<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: LmdbRawIfUnaligned + PartialOrd<T>> PartialOrd for Unaligned<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
Source§

fn lt(&self, other: &Self) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn le(&self, other: &Self) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn gt(&self, other: &Self) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

fn ge(&self, other: &Self) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Pointer for Unaligned<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T: LmdbRawIfUnaligned + Rem<T>> Rem for Unaligned<T>

Source§

type Output = Unaligned<<T as Rem>::Output>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + RemAssign<T>> RemAssign for Unaligned<T>

Source§

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + Shl<T>> Shl for Unaligned<T>

Source§

type Output = Unaligned<<T as Shl>::Output>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: Self) -> Self::Output

Performs the << operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + ShlAssign<T>> ShlAssign for Unaligned<T>

Source§

fn shl_assign(&mut self, rhs: Self)

Performs the <<= operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + Shr<T>> Shr for Unaligned<T>

Source§

type Output = Unaligned<<T as Shr>::Output>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: Self) -> Self::Output

Performs the >> operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + ShrAssign<T>> ShrAssign for Unaligned<T>

Source§

fn shr_assign(&mut self, rhs: Self)

Performs the >>= operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + Sub<T>> Sub for Unaligned<T>

Source§

type Output = Unaligned<<T as Sub>::Output>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: LmdbRawIfUnaligned + SubAssign<T>> SubAssign for Unaligned<T>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<T> UpperExp for Unaligned<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> UpperHex for Unaligned<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T: LmdbRawIfUnaligned> Copy for Unaligned<T>

Source§

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<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<V> AsLmdbBytes for V
where V: LmdbRaw,

Source§

fn as_lmdb_bytes(&self) -> &[u8]

Casts the given reference to a byte slice appropriate for storage in LMDB.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<'a, T> DefaultFeatures<'a> for T
where T: 'a + Send + Sync + Clone,

Source§

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§

fn self_address_mut(&mut self) -> *mut ()

Returns the address of self. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<V> FromLmdbBytes for V
where V: LmdbRaw,

Source§

fn from_lmdb_bytes(bytes: &[u8]) -> Result<&V, String>

Given a byte slice, return an instance of Self described, or Err with an error message if the given byte slice is not an appropriate value.
Source§

impl<V> FromReservedLmdbBytes for V
where V: LmdbRaw,

Source§

unsafe fn from_reserved_lmdb_bytes(bytes: &mut [u8]) -> &mut V

Given a mutable byte slice containing arbitrary data, return an instance of Self. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LmdbOrdKeyIfUnaligned for T
where T: LmdbRaw + LmdbOrdKey,

Source§

fn ordered_by_bytes() -> bool

Like LmdbOrdKey::ordered_by_bytes()
Source§

fn ordered_as_integer() -> bool

Like LmdbOrdKey::ordered_as_integer()
Source§

impl<T> LmdbRawIfUnaligned for T
where T: LmdbRaw,

Source§

fn reported_type() -> String

Returns the name of this type to report in error messages. Read more
Source§

impl<'a, T> NonSyncFeatures<'a> for T
where T: 'a + Clone,

Source§

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.
Source§

fn self_address_mut(&mut self) -> *mut ()

Returns the address of self. Read more
Source§

impl<T> SafeBorrow<T> for T
where T: ?Sized,

Source§

fn borrow_replacement(ptr: &T) -> &T

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.