Back to Flutter Rust Bridge

Trait definitions

website/docs/guides/traits/definitions.md

2.12.0480 B
Original Source

Trait definitions

The trait definitions will be automatically converted to Dart abstract classes.

The non-instance method (i.e. static method) will not be generated, since Dart, unlike Rust, does not support such methods being implemented by subclasses.

Example

For example, suppose we write down:

rust
pub trait MyTrait {
    fn f(&self, a: String) -> i32;
}

It will become an abstract base class like:

dart
abstract class MyTrait {
  int f(String a);
}