Skip to main content

DataClassDecl

Struct DataClassDecl 

Source
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

Source

pub fn new(rust_type: Type) -> Self

Source

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

Override the Kotlin class name (relative, no dots).

Source

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.

Source

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

Source

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.

Source

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

Source

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.

Source

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

Source§

fn from(d: DataClassDecl) -> Self

Converts to this type from the input type.
Source§

impl From<Type> for DataClassDecl

Source§

fn from(rust_type: Type) -> 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.