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
impl ExpandParamDecl
pub fn new(rust_type: Type) -> Self
Sourcepub fn rust_type(&self) -> &Origin<Type>
pub fn rust_type(&self) -> &Origin<Type>
The type this declaration was written with, as originally parsed.
Sourcepub fn variants(&self) -> &[LocalVariant]
pub fn variants(&self) -> &[LocalVariant]
The declared build-from / existing-handle arms, in declaration order.
pub(crate), not pub — LocalVariant itself is pub(crate)
(a public fn cannot return a private type).
Sourcepub fn is_no_split(&self) -> bool
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).
Sourcepub fn variant(self, ctor: FunctionDecl) -> Self
pub fn variant(self, ctor: FunctionDecl) -> Self
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.
Sourcepub fn variant_self(self) -> Self
pub fn variant_self(self) -> Self
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.
Sourcepub fn no_split(self) -> Self
pub fn no_split(self) -> Self
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
impl Clone for ExpandParamDecl
Source§fn clone(&self) -> ExpandParamDecl
fn clone(&self) -> ExpandParamDecl
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl From<ExpandParamDecl> for ExpandDecl
impl From<ExpandParamDecl> for ExpandDecl
Source§fn from(d: ExpandParamDecl) -> Self
fn from(d: ExpandParamDecl) -> Self
Auto Trait Implementations§
impl !Send for ExpandParamDecl
impl !Sync for ExpandParamDecl
impl Freeze for ExpandParamDecl
impl RefUnwindSafe for ExpandParamDecl
impl Unpin for ExpandParamDecl
impl UnsafeUnpin for ExpandParamDecl
impl UnwindSafe for ExpandParamDecl
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