pub struct Alignment { /* private fields */ }ptr_alignment_type)crypto and std only.Expand description
A type storing a usize which is a power of two, and thus
represents a possible alignment in the Rust abstract machine.
Note that particularly large alignments, while representable in this type, are likely not to be supported by actual allocators and linkers.
Implementations§
Source§impl Alignment
impl Alignment
Sourcepub const MIN: Alignment
🔬This is a nightly-only experimental API. (ptr_alignment_type)Available on crate feature rustls only.
pub const MIN: Alignment
ptr_alignment_type)rustls only.The smallest possible alignment, 1.
All addresses are always aligned at least this much.
§Examples
#![feature(ptr_alignment_type)]
use std::mem::Alignment;
assert_eq!(Alignment::MIN.as_usize(), 1);Sourcepub const fn of<T>() -> Alignment
🔬This is a nightly-only experimental API. (ptr_alignment_type)Available on crate feature rustls only.
pub const fn of<T>() -> Alignment
ptr_alignment_type)rustls only.Returns the alignment for a type.
This provides the same numerical value as align_of,
but in an Alignment instead of a usize.
Sourcepub const fn of_val<T>(val: &T) -> Alignmentwhere
T: ?Sized,
🔬This is a nightly-only experimental API. (ptr_alignment_type)Available on crate feature rustls only.
pub const fn of_val<T>(val: &T) -> Alignmentwhere
T: ?Sized,
ptr_alignment_type)rustls only.Sourcepub const unsafe fn of_val_raw<T>(val: *const T) -> Alignmentwhere
T: ?Sized,
🔬This is a nightly-only experimental API. (ptr_alignment_type)Available on crate feature rustls only.
pub const unsafe fn of_val_raw<T>(val: *const T) -> Alignmentwhere
T: ?Sized,
ptr_alignment_type)rustls only.Returns the ABI-required minimum alignment of the type of the value that val points to.
Every reference to a value of the type T must be a multiple of this number.
§Safety
This function is only safe to call if the following conditions hold:
- If
TisSized, this function is always safe to call. - If the unsized tail of
Tis:- a slice, then the length of the slice tail must be an initialized
integer, and the size of the entire value
(dynamic tail length + statically sized prefix) must fit in
isize. For the special case where the dynamic tail length is 0, this function is safe to call. - a trait object, then the vtable part of the pointer must point
to a valid vtable acquired by an unsizing coercion, and the size
of the entire value (dynamic tail length + statically sized prefix)
must fit in
isize. - an (unstable) extern type, then this function is always safe to
call, but may panic or otherwise return the wrong value, as the
extern type’s layout is not known. This is the same behavior as
Alignment::of_valon a reference to a type with an extern type tail. - otherwise, it is conservatively not allowed to call this function.
- a slice, then the length of the slice tail must be an initialized
integer, and the size of the entire value
(dynamic tail length + statically sized prefix) must fit in
§Examples
#![feature(ptr_alignment_type)]
use std::mem::Alignment;
assert_eq!(unsafe { Alignment::of_val_raw(&5i32) }.as_usize(), 4);Sourcepub const fn new(align: usize) -> Option<Alignment>
🔬This is a nightly-only experimental API. (ptr_alignment_type)Available on crate feature rustls only.
pub const fn new(align: usize) -> Option<Alignment>
ptr_alignment_type)rustls only.Creates an Alignment from a usize, or returns None if it’s
not a power of two.
Note that 0 is not a power of two, nor a valid alignment.
Sourcepub const unsafe fn new_unchecked(align: usize) -> Alignment
🔬This is a nightly-only experimental API. (ptr_alignment_type)Available on crate feature rustls only.
pub const unsafe fn new_unchecked(align: usize) -> Alignment
ptr_alignment_type)rustls only.Creates an Alignment from a power-of-two usize.
§Safety
align must be a power of two.
Equivalently, it must be 1 << exp for some exp in 0..usize::BITS.
It must not be zero.
Sourcepub const fn as_usize(self) -> usize
🔬This is a nightly-only experimental API. (ptr_alignment_type)Available on crate feature rustls only.
pub const fn as_usize(self) -> usize
ptr_alignment_type)rustls only.Returns the alignment as a usize.
Sourcepub const fn as_nonzero(self) -> NonZero<usize>
👎Deprecated since 1.96.0: renamed to as_nonzero_usize
🔬This is a nightly-only experimental API. (ptr_alignment_type)Available on crate feature rustls only.
pub const fn as_nonzero(self) -> NonZero<usize>
renamed to as_nonzero_usize
ptr_alignment_type)rustls only.Sourcepub const fn as_nonzero_usize(self) -> NonZero<usize>
🔬This is a nightly-only experimental API. (ptr_alignment_type)Available on crate feature rustls only.
pub const fn as_nonzero_usize(self) -> NonZero<usize>
ptr_alignment_type)rustls only.Sourcepub const fn log2(self) -> u32
🔬This is a nightly-only experimental API. (ptr_alignment_type)Available on crate feature rustls only.
pub const fn log2(self) -> u32
ptr_alignment_type)rustls only.Returns the base-2 logarithm of the alignment.
This is always exact, as self represents a power of two.
§Examples
#![feature(ptr_alignment_type)]
use std::ptr::Alignment;
assert_eq!(Alignment::of::<u8>().log2(), 0);
assert_eq!(Alignment::new(1024).unwrap().log2(), 10);Sourcepub const fn mask(self) -> usize
🔬This is a nightly-only experimental API. (ptr_alignment_type)Available on crate feature rustls only.
pub const fn mask(self) -> usize
ptr_alignment_type)rustls only.Returns a bit mask that can be used to match this alignment.
This is equivalent to !(self.as_usize() - 1).
§Examples
#![feature(ptr_mask)]
#![feature(ptr_alignment_type)]
use std::mem::Alignment;
use std::ptr::NonNull;
#[repr(align(1))] struct Align1(u8);
#[repr(align(2))] struct Align2(u16);
#[repr(align(4))] struct Align4(u32);
let one = <NonNull<Align1>>::dangling().as_ptr();
let two = <NonNull<Align2>>::dangling().as_ptr();
let four = <NonNull<Align4>>::dangling().as_ptr();
assert_eq!(four.mask(Alignment::of::<Align1>().mask()), four);
assert_eq!(four.mask(Alignment::of::<Align2>().mask()), four);
assert_eq!(four.mask(Alignment::of::<Align4>().mask()), four);
assert_ne!(one.mask(Alignment::of::<Align4>().mask()), one);Trait Implementations§
Source§impl Default for Alignment
Returns Alignment::MIN, which is valid for any type.
impl Default for Alignment
Returns Alignment::MIN, which is valid for any type.
Source§impl Ord for Alignment
impl Ord for Alignment
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Alignment
impl PartialOrd for Alignment
impl Copy for Alignment
impl Eq for Alignment
impl StructuralPartialEq for Alignment
Auto Trait Implementations§
impl Freeze for Alignment
impl RefUnwindSafe for Alignment
impl Send for Alignment
impl Sync for Alignment
impl Unpin for Alignment
impl UnsafeUnpin for Alignment
impl UnwindSafe for Alignment
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>
§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writer§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writer§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writer§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writer§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer