Skip to main content

ExpandParamDecl

Struct ExpandParamDecl 

Source
pub struct ExpandParamDecl { /* private fields */ }
Expand description

Declares a type’s default input boundary: how a parameter of this type may be supplied, as a list of variants — “built from this constructor’s ingredients, OR that one’s, OR passed as an existing handle”. Applies to every function with a parameter of the type; a single function opts out or narrows via FunctionDecl::expand_param.

Build one with expand_param!, add arms with variant / variant_self, and hand it to the adapter’s expand declaration.

Generated shape — at the wire tier this is a selector dispatch: with more than one arm the parameter crosses as a selector Int plus one nullable slot per arm (keyExprSel: Int, keyExpr0: String?, keyExpr1: KeyExpr?), and the raw call site passes (0, "key", null)-style tuples. That selector form is always emitted; the wrapper’s generated KDoc shape-notes document the exact slots per function.

Splittability (checked) — a multi-variant declaration must be splittable: its arms must surface as distinct JVM signatures, so a function can request idiomatic typed overloads on top of the selector form (f(key: String, …) / f(key: KeyExpr, …)) via FunctionDecl::split_on_param. This is verified up front — two arms with the same erased parameter types are a hard build error. .no_split() suppresses that check for a variant set that will only ever be used as the selector form. The type-level declaration itself emits no overloads; emission is per-function via .split_on_param. The selector form always stays public, so consumers can also add their own same-named overloads by hand.

The type does not have to be declared in any package. A boundary decl on an undeclared type makes it rust-side-only: the value is always built from its ingredients at the boundary and never materializes in Kotlin — no class, no handle, nothing to close(). The one restriction is structural: variant_self hard-errors for such a type, since there is no Kotlin object to pass.

// A KeyExpr param accepts EITHER a String (built via keyexpr_new_try_from)
// OR an existing KeyExpr handle:
let _ = prebindgen_registry::expand_param!(KeyExpr)
    .variant(prebindgen_registry::fun!(keyexpr_new_try_from))
    .variant_self();

Implementations§

Source§

impl ExpandParamDecl

Source

pub fn new(rust_type: Type) -> ExpandParamDecl

Source

pub fn key(&self) -> &TypeKey

The type identity this declaration is registered under.

Source

pub fn rust_type(&self) -> &Origin<Type>

The type this declaration was written with, as originally parsed.

Source

pub fn variants(&self) -> &[LocalVariant]

The declared build-from / existing-handle arms, in declaration order. pub(crate), not pubLocalVariant itself is pub(crate) (a public fn cannot return a private type).

Source

pub fn is_no_split(&self) -> bool

Whether .no_split() was declared (suppresses the splittability check). Named is_no_split rather than no_split — that name is already the builder method that sets the flag (Self::no_split).

Source

pub fn variant(self, ctor: FunctionDecl) -> ExpandParamDecl

Add a build-from arm: parameters of this type also carry the named #[prebindgen] constructor’s inputs on the wire, and Rust builds the value in the same call. E.g. keyexpr_new_try_from(&str) gives every function taking a KeyExpr a String-carrying arm — as a selector + nullable slot at the wire tier (see the type-level docs for the exact generated shape), not as a Kotlin overload.

A variant arm only names the constructor: no Kotlin surface of its own, so a decorated fun! (.name() / expand overrides) is a hard error rather than a silent discard.

Source

pub fn variant_self(self) -> ExpandParamDecl

Add the existing-handle arm: also accept an already-built value. On its own this is simply the default (a bare handle), so declaring it alone changes nothing; it earns its place next to build variants.

Source

pub fn no_split(self) -> ExpandParamDecl

Suppress the splittability check. A multi-variant expansion is verified up front to be splittable (its arms surface as distinct JVM signatures) so that FunctionDecl::split_on_param can emit idiomatic typed overloads. .no_split() opts this variant set out of that check — declare it when two arms genuinely share a JVM signature and you only ever want the selector form (a function that then tries to .split_on_param such a parameter gets the concrete ambiguity error).

A no-op on a single-variant declaration (nothing to check).

Trait Implementations§

Source§

impl Clone for ExpandParamDecl

Source§

fn clone(&self) -> ExpandParamDecl

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 From<ExpandParamDecl> for ExpandDecl

Source§

fn from(d: ExpandParamDecl) -> ExpandDecl

Converts to this type from the input type.

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.