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>.
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.
Array
[T; N] — a run of T whose length is known at compile time.
Fields
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.
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.
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.
Unit
().
Trait Implementations§
Auto Trait Implementations§
impl !Send for TypeKind
impl !Sync for TypeKind
impl Freeze for TypeKind
impl RefUnwindSafe for TypeKind
impl Unpin for TypeKind
impl UnsafeUnpin for TypeKind
impl UnwindSafe for TypeKind
Blanket Implementations§
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,
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