pub struct FunctionDecl { /* private fields */ }Expand description
Declares one #[prebindgen] function to export. The adapter either adds it
to a package or attaches it to a class as a method or a factory.
Build it from a bare Rust name with fun! and chain
name to set its Kotlin name.
expand_param / expand_return
override, for this one function, the boundary defaults its
parameter/return types declare at the generator level
— using the very same decl objects, so the complete-set rule is identical
at both scopes.
Implementations§
Source§impl FunctionDecl
impl FunctionDecl
pub fn new(rust_ident: Ident) -> FunctionDecl
Sourcepub fn rust_ident(&self) -> &Ident
pub fn rust_ident(&self) -> &Ident
The Rust-side fn ident (the path’s last segment for a binding-local fn).
Sourcepub fn kotlin_name_override(&self) -> &Option<String>
pub fn kotlin_name_override(&self) -> &Option<String>
The explicit Kotlin-side name, if .name(...) was declared.
Sourcepub fn param_expands(&self) -> &[(String, ExpandParamDecl)]
pub fn param_expands(&self) -> &[(String, ExpandParamDecl)]
The per-parameter expand overrides declared with .expand_param(...).
Sourcepub fn return_expand(&self) -> &Option<ExpandReturnDecl>
pub fn return_expand(&self) -> &Option<ExpandReturnDecl>
The return expand override declared with .expand_return(...), if any.
Sourcepub fn split_on_params(&self) -> &[String]
pub fn split_on_params(&self) -> &[String]
The parameters named with .split_on_param(...), in declaration order.
Sourcepub fn local(&self) -> &Option<(Path, Option<Signature>)>
pub fn local(&self) -> &Option<(Path, Option<Signature>)>
The binding-local fn’s declared path and stated signature, if this is
a fun!(crate::f) rather than an ordinary #[prebindgen] registry fn.
Sourcepub fn into_parts(
self,
) -> (Ident, Option<String>, Vec<(String, ExpandParamDecl)>, Option<ExpandReturnDecl>, Vec<String>, Option<(Path, Option<Signature>)>)
pub fn into_parts( self, ) -> (Ident, Option<String>, Vec<(String, ExpandParamDecl)>, Option<ExpandReturnDecl>, Vec<String>, Option<(Path, Option<Signature>)>)
Consume self into its raw fields, by value. Not a plain accessor —
the one call site (accept_fn_expands in the JNI builder) destructures
a whole FunctionDecl it owns to move each field (Vecs, the local
signature) onward without cloning, so a reference-returning accessor
won’t do.
Sourcepub fn new_local(path: Path) -> FunctionDecl
pub fn new_local(path: Path) -> FunctionDecl
fun!(crate::f) — declare a binding-local fn by path. The fn
ident (the path’s last segment) names it everywhere a registry fn’s
ident would; chain sig to state its signature.
Sourcepub fn sig(self, signature: Signature) -> FunctionDecl
pub fn sig(self, signature: Signature) -> FunctionDecl
Sourcepub fn name(self, kotlin_name: impl Into<String>) -> FunctionDecl
pub fn name(self, kotlin_name: impl Into<String>) -> FunctionDecl
Set the Kotlin-side name. Default: the Rust name camel-cased
(session_declare_publisher → sessionDeclarePublisher).
Sourcepub fn expand_param(
self,
param: impl AsRef<str>,
decl: ExpandParamDecl,
) -> FunctionDecl
pub fn expand_param( self, param: impl AsRef<str>, decl: ExpandParamDecl, ) -> FunctionDecl
Override, for the named parameter of this function only, how that
parameter is supplied — with the same ExpandParamDecl a type-level
default uses, so the complete-set rule applies here too: the decl
states the entire variant set for this param (a lone .variant_self()
= “only a ready-made handle”, replacing the type’s build variants —
e.g. un-declaring a key expression needs the handle, not a string).
param is the Rust parameter name; the decl’s type is cross-checked
against that parameter’s (peeled) type at generation time — an unknown
parameter or a type mismatch is a hard error. Call again with a
different param to override several parameters independently;
declaring the same parameter twice is a hard error.
Sourcepub fn split_on_param(self, param: impl AsRef<str>) -> FunctionDecl
pub fn split_on_param(self, param: impl AsRef<str>) -> FunctionDecl
Emit idiomatic typed Kotlin overloads for this parameter. By default
a multi-variant expanded parameter crosses only as the selector tuple
(expectedSel: Int, expected0: …, expected1: …). .split_on_param("p")
additionally emits, alongside the selector wrapper, one typed overload
per variant of p — f(count: Long, total: Double, …) for a
summary_new(count, total) arm, f(expected: Summary, …) for
variant_self() — each delegating to the selector form.
The parameter’s variant set must be splittable (its arms surface as
distinct JVM signatures) — enforced up front on the
expand_param! declaration unless it opted out
with .no_split().
Call again for several parameters: the generated overloads are then the cartesian product of the named parameters’ arms. That concrete product must have no two combinations sharing a JVM signature — a hard build error if it does.
An Option<…> parameter splits through its single-leaf arms only
(nullable-arm rule): the overload keeps the arm’s nullable type and
null selects absence — f(encoding: Encoding?, …) for a
variant_self() arm of an Option<&Encoding> parameter. Multi-leaf
arms stay selector-only; an optional parameter with no single-leaf arm
is a hard error.
param is the Rust parameter name; it must be an expanded,
multi-variant parameter of this function (unknown / single-variant /
recursively-built ⇒ a hard error). Declaring the same parameter twice
is a hard error.
Sourcepub fn expand_return(self, decl: ExpandReturnDecl) -> FunctionDecl
pub fn expand_return(self, decl: ExpandReturnDecl) -> FunctionDecl
Override this function’s return decomposition — with the same
ExpandReturnDecl a type-level default uses, stating the complete
field set (a lone .field_self() = the raw whole value, which for a
borrowed &T / Option<&T> return crosses by cloning into a fresh
owned handle). The decl’s type is cross-checked against the function’s
(peeled) return type at generation time — a mismatch is a hard error.
At most one per function.
Trait Implementations§
Source§impl From<FunctionDecl> for ConvertSourceDecl
impl From<FunctionDecl> for ConvertSourceDecl
Source§fn from(decl: FunctionDecl) -> ConvertSourceDecl
fn from(decl: FunctionDecl) -> ConvertSourceDecl
Source§impl From<FunctionDecl> for IgnoreDecl
impl From<FunctionDecl> for IgnoreDecl
Source§fn from(decl: FunctionDecl) -> Self
fn from(decl: FunctionDecl) -> Self
Auto Trait Implementations§
impl !Send for FunctionDecl
impl !Sync for FunctionDecl
impl Freeze for FunctionDecl
impl RefUnwindSafe for FunctionDecl
impl Unpin for FunctionDecl
impl UnsafeUnpin for FunctionDecl
impl UnwindSafe for FunctionDecl
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> 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