Skip to main content

ArrayExtent

Struct ArrayExtent 

Source
pub struct ArrayExtent {
    pub value: usize,
    pub source: ExtentSource,
    pub origin: Origin<Expr>,
}
Expand description

A fixed-size array’s extent: the number, the const identity when the source named one, and the spelling it was written with.

§Three facts, three consumers — and no ==

The three answer different questions, and deliberately no equality is provided, because there is no single one that could be right. A consumer projects the fact it actually needs:

QuestionProjection
is this the same type / the same converter?Self::value
how does a C declaration spell it?Self::origin.syntax, per occurrence
which consts must reach the header as a #define?Self::const_id

A blanket == mixes them and is wrong under either reading: comparing source makes [u8; A] differ from [u8; 4] when A == 4 — one Rust type reported as two — while ignoring the spelling makes [u8; 4] equal [u8; 0x04], whose retained syntax differs. Neither is type identity and neither is spelling identity, so the choice belongs to whoever is asking.

§Note for a converter table

value being the type identity means several occurrences share one converter, and their spellings differ. A shared converter therefore needs a canonical Rust spelling chosen on purpose — the evaluated literal is the obvious one — rather than whichever occurrence happened to populate a deduplicated entry.

This lives on the use site — a field’s or parameter’s type — and never on anything keyed by type, for the same reason: two occurrences of one type may name the length differently, so a type-keyed table could only report whichever was stored last.

Fields§

§value: usize

The evaluated length. The type identity: [u8; A] and [u8; 4] are one Rust type when A == 4, and a destination language with no way to name a Rust const needs the number.

§source: ExtentSource

How the length was addressed, so a C header can re-state uint8_t tag[TAG_LEN] and know TAG_LEN must reach it.

§origin: Origin<Expr>

The length expression as written — 4, 0x04, TAG_LEN — and where it came from. The spelling of this occurrence, which is what a declaration re-emits; two occurrences of one type may differ here.

Implementations§

Source§

impl ArrayExtent

Source

pub fn const_id(&self) -> Option<&ConstId>

The const this extent named, if it named one.

Trait Implementations§

Source§

impl Clone for ArrayExtent

Source§

fn clone(&self) -> ArrayExtent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ArrayExtent

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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