pub enum ConvertSpec {
PrebindgenFn(Ident),
Trait {
repr: Type,
fallible: bool,
},
}Expand description
Declares a type’s canonical single-value conversion: how one value of
the type crosses the boundary wherever a single value is needed — as a
parameter or return, inside Option<_> / Vec<_> / the Result<T, E>
success position, as a data_class field. Each direction takes one
ConvertSourceDecl:
.convert(convert!(Millis)
.input(fun!(millis_from_long)) // fn(u64) -> Millis (wire → rust)
.output(fun!(millis_value)) // fn(&Millis) -> u64 (rust → wire)
.valid_range(0u64..=86_400_000)) // rejects invalid values; Option uses a niche
.convert(convert!(Celsius).input(from!(i32)).output(into!(i32)))
.convert(convert!(Label)
.input(try_from!(String).with(path!(crate::label_in)).error(ty!(String)))
.output(into!(String).with(path!(crate::label_out))))The foreign surface derives from the conversion’s other-side type
(u64 ⇒ Kotlin ULong / C uint64_t) — nothing is stated verbatim.
valid_range and
valid_values declare the legal subset of a
scalar representation. Generated converters validate the subset, and
adapters may reuse values outside it as allocation-free Option/Result
markers; exclude_values reserves holes in
an otherwise legal domain. A try_ source’s Err
routes to the caller’s error handler. Conversion fns may live in the flat
crate or in a helper crate whose item stream is chained into the same
prebindgen_flat::Flat::builder parse; generated calls qualify each
function with its origin crate.
Distinct from the expand_param! /
expand_return! boundary decls: those reshape a
function boundary into multiple leaves (variants in / fields out),
while convert! defines the type’s one-value form used everywhere else.
A type may declare both — expansion wins at the fn boundaries where it is
declared; the conversion serves every other position. The method names
differ deliberately: converters are direction-things (input
also serves callback returns, output also serves
callback arguments), while expansion decls are position-things.
One direction’s conversion source — where the conversion code comes
from, the lowered form of a ConvertSourceDecl.
Variants§
PrebindgenFn(Ident)
A #[prebindgen] fn (flat or helper crate): the representable type
and fallibility are read from its registry signature at lookup time.
Trait
A core::convert trait impl; the representable type is stated
explicitly (there is no signature to read). fallible selects
TryInto (the associated Error routes to the caller’s error
handler) vs Into.
Implementations§
Trait Implementations§
Source§impl Clone for ConvertSpec
impl Clone for ConvertSpec
Source§fn clone(&self) -> ConvertSpec
fn clone(&self) -> ConvertSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Send for ConvertSpec
impl !Sync for ConvertSpec
impl Freeze for ConvertSpec
impl RefUnwindSafe for ConvertSpec
impl Unpin for ConvertSpec
impl UnsafeUnpin for ConvertSpec
impl UnwindSafe for ConvertSpec
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