Skip to main content

TypeKind

Enum TypeKind 

Source
pub enum TypeKind {
Show 15 variants Scalar(ScalarKind), Str, String, Optional(Box<TypeRef>), Vec(Box<TypeRef>), Slice(Box<TypeRef>), Fallible { ok: Box<TypeRef>, err: Box<TypeRef>, }, Named { id: TypeId, args: Vec<GenericArg>, }, Array { elem: Box<TypeRef>, extent: Box<ArrayExtent>, }, Ref { lifetime: Option<Lifetime>, mutable: bool, inner: Box<TypeRef>, }, Boxed(Box<TypeRef>), Cow { lifetime: Lifetime, inner: Box<TypeRef>, }, Uninit(Box<TypeRef>), Callback { args: Vec<TypeRef>, }, Unit,
}
Expand description

The accepted syntax of a TypeRef: the subset of syn::Type a #[prebindgen] crate may write, and nothing more.

One variant per accepted Rust form, not per destination concept. str and String are two forms and get two variants; Box<T> is a form of its own and does not disappear into T. Nothing here folds two spellings together, which is what makes TypeRef::spell recoverable from this — rebuilding the syntax from a kind is the round-trip that checks it.

§Why it is only syntax

It was a destination-neutral classification once, and that leaked: &T earned a layer while Box<T> was declared transparent, on no principle either adapter shared, and Cbindgen went on picking its C type from the Rust spelling anyway. Deciding that &str and String are both “a string” is a destination decision, so it belongs to the destination — the model hands over what the source wrote and stays out of it.

Where two adapters want the same fold, it is a reading, not a variant: TypeRef::unwrapped peels Box/Cow for the consumers that want them gone, and the ones that must rebuild the Rust value ask TypeRef::erased_wrappers instead. One helper, visible at the call site, rather than a fold baked into every classification.

Variants§

§

Scalar(ScalarKind)

A primitive with a fixed C/JVM counterpart — u8, bool, f64.

A closed set of bare idents, so recognising one is reading the syntax rather than interpreting it — and it keeps every adapter off a name table of its own.

§

Str

str — unsized, so it is only ever reached through a Ref or a wrapper.

§

String

String.

§

Optional(Box<TypeRef>)

Option<T>.

§

Vec(Box<TypeRef>)

Vec<T>.

§

Slice(Box<TypeRef>)

[T] — the unsized run, reached through a Ref or a wrapper. Not the same form as Vec, so not the same variant.

§

Fallible

Result<T, E>.

Fields

§

Named

Any other named type: a #[prebindgen] struct or enum, or a foreign path.

id is the type’s identity — a name, not a syn::Path, so nothing downstream has to take a path apart to learn what a type is. args is the last segment’s generic arguments, in the order they were written and including lifetimes, because dropping either would make the spelling unrecoverable.

Fields

§

Array

[T; N] — a run of T whose length is known at compile time.

Fields

§elem: Box<TypeRef>
§extent: Box<ArrayExtent>

Boxed: an extent carries an Origin over the length expression, which makes it the size outlier among the kinds, and an array is the rare one. The same trade-off Unsupported::error makes.

§

Ref

A borrow — &T or &mut T, with the lifetime the source wrote.

An out-parameter is &mut over Uninit, which is what the source spells. What that means at a boundary — the caller supplies the slot, the callee fills it — is the adapter’s reading of the form, not a third value of a mode enum.

Fields

§lifetime: Option<Lifetime>
§mutable: bool
§inner: Box<TypeRef>
§

Boxed(Box<TypeRef>)

Box<T>.

A form of its own. It was erased once, on the grounds that no destination language can tell Box<T> from T — true, and still the adapter’s call to make: TypeRef::unwrapped makes it, on demand.

§

Cow

Cow<'a, T>.

The lifetime is not optional: Cow has one in its own signature, so a Cow<T> is not Rust and no source crate can compile it. Lowering refuses the shape (WrongGenericArguments) rather than modelling an absence that would then have to be spelled back as something the source did not write.

Fields

§lifetime: Lifetime
§inner: Box<TypeRef>
§

Uninit(Box<TypeRef>)

MaybeUninit<T>.

Accepted only directly under a &mut — see UnsupportedTypeReason::OwnedUninit. It has a variant because the source writes it; that it is refused elsewhere is an acceptance rule, which is a separate question from how the form is represented.

§

Callback

impl Fn(A, B, …) + Send + Sync + 'static — the callback form.

Fields

§args: Vec<TypeRef>
§

Unit

().

Trait Implementations§

Source§

impl Clone for TypeKind

Source§

fn clone(&self) -> TypeKind

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 TypeKind

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.