pub struct DataClassDecl { /* private fields */ }Expand description
Declares a Rust struct as a Kotlin data class. Its fields cross the
boundary individually and Kotlin reassembles the object with a generated
fromParts(...) — no Rust-side heap object, no handle to close. Use this
for plain immutable data you copy across, as opposed to
ptr_class! handles.
Members work like every class kind whose instance can re-enter Rust —
here the receiver re-enters as its field leaves (the same call-site
destructuring a data-class parameter gets), just rebased to this.
Implementations§
Source§impl DataClassDecl
impl DataClassDecl
pub fn new(rust_type: Type) -> Self
Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Override the Kotlin class name (relative, no dots).
Sourcepub fn jobject_input(self) -> Self
pub fn jobject_input(self) -> Self
Explicitly keep this data class object-shaped on the Kotlin → Rust
boundary. By default a data class must flatten completely into its
transitive field leaves; generation fails rather than silently falling
back to Rust-side JObject field reads. This escape hatch is intended
for recursive/identity-bearing graphs, legacy ABI compatibility, or a
deliberately chosen object boundary.
When the marked type is nested inside an unmarked data class, only the
marked branch crosses as a JObject; its siblings remain flattened.
Rust → Kotlin output construction is unaffected.
Sourcepub fn interface(self) -> Self
pub fn interface(self) -> Self
Emit a generated Kotlin interface mirroring this class’s
public instance surface, and make the class implement it (every
class-body member gains the override modifier). The interface
is named by interface_name, else the
JniGenBuilder::set_interface_name_mangle hook over the final class
name (default: append "Api").
This is the compiler-checked half of the integration hatch: a
hand-written interface that extends the generated one can build
default members over the class’s real signatures — no
hand-replication. Pair it with implements
to attach that hand-written interface to the class. (For
behavior-only injection, a Kotlin extension function needs no
declaration at all.)
Sourcepub fn interface_name(self, name: impl Into<String>) -> Self
pub fn interface_name(self, name: impl Into<String>) -> Self
Name the generated interface literally (relative, no dots),
bypassing the JniGenBuilder::set_interface_name_mangle hook.
Implies interface.
Sourcepub fn implements(self, iface: impl Into<String>) -> Self
pub fn implements(self, iface: impl Into<String>) -> Self
Add a Kotlin interface to the generated class’s supertype
list — the class implements it nominally: its abstract members
must be satisfied by the generated surface or carry default
implementations. iface is an FQN (dotted names are imported and
shortened) or a same-package name; call again to add several.
Orthogonal to interface — but to abstract
over the class’s own members from your interface, enable the
generated interface and make yours extend it (that is what turns
mismatches into compile errors in YOUR file).
Sourcepub fn method(self, rust_fun: FunctionDecl) -> Self
pub fn method(self, rust_fun: FunctionDecl) -> Self
Expose a #[prebindgen] reader (f(&Self) -> R) as an instance
method on the generated data class (see PtrClassDecl::method) — the
receiver crosses as this’s field leaves, exactly like a data-class
parameter.
Sourcepub fn constructor(self, rust_fun: FunctionDecl) -> Self
pub fn constructor(self, rust_fun: FunctionDecl) -> Self
Expose a #[prebindgen] factory as a companion-object factory
(see PtrClassDecl::constructor).
Trait Implementations§
Source§impl From<DataClassDecl> for ClassDecl
impl From<DataClassDecl> for ClassDecl
Source§fn from(d: DataClassDecl) -> Self
fn from(d: DataClassDecl) -> Self
Auto Trait Implementations§
impl !Send for DataClassDecl
impl !Sync for DataClassDecl
impl Freeze for DataClassDecl
impl RefUnwindSafe for DataClassDecl
impl Unpin for DataClassDecl
impl UnsafeUnpin for DataClassDecl
impl UnwindSafe for DataClassDecl
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