Skip to main content

ConvertSpec

Enum ConvertSpec 

Source
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.

Fields

§repr: Type
§fallible: bool

Implementations§

Source§

impl ConvertSpec

Source

pub fn describe(&self) -> String

One-line human description of the source kind (report use).

Trait Implementations§

Source§

impl Clone for ConvertSpec

Source§

fn clone(&self) -> ConvertSpec

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

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.