Skip to main content

FunctionDecl

Struct FunctionDecl 

Source
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

Source

pub fn new(rust_ident: Ident) -> FunctionDecl

Source

pub fn rust_ident(&self) -> &Ident

The Rust-side fn ident (the path’s last segment for a binding-local fn).

Source

pub fn kotlin_name_override(&self) -> &Option<String>

The explicit Kotlin-side name, if .name(...) was declared.

Source

pub fn param_expands(&self) -> &[(String, ExpandParamDecl)]

The per-parameter expand overrides declared with .expand_param(...).

Source

pub fn return_expand(&self) -> &Option<ExpandReturnDecl>

The return expand override declared with .expand_return(...), if any.

Source

pub fn split_on_params(&self) -> &[String]

The parameters named with .split_on_param(...), in declaration order.

Source

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.

Source

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.

Source

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.

Source

pub fn sig(self, signature: Signature) -> FunctionDecl

State a binding-local fn’s exact Rust signature (build it with sig!) — a path carries no signature to read. The parameter names become the foreign-side parameter names. Required for a path-built fun!; a hard error on a registry fn (its signature is read from the registry).

Source

pub fn name(self, kotlin_name: impl Into<String>) -> FunctionDecl

Set the Kotlin-side name. Default: the Rust name camel-cased (session_declare_publishersessionDeclarePublisher).

Source

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.

Source

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 pf(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.

Source

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

Source§

fn from(decl: FunctionDecl) -> ConvertSourceDecl

Converts to this type from the input type.
Source§

impl From<FunctionDecl> for IgnoreDecl

Source§

fn from(decl: FunctionDecl) -> Self

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