Use this page with an LLM
Constants
BoltFFI exports two kinds of constants:
- A global constant is a standalone Rust
constmarked with#[export]. - An associated constant belongs to an exported record, enum, or class.
Both forms produce immutable values in the generated API. BoltFFI emits simple literals directly in generated source and reads values that require Rust evaluation through a generated native accessor.
Use a global constant for a value that belongs to the package as a whole. Use an associated constant when the value describes a particular record, enum, or class.
Global constants
Mark a standalone public constant with #[export]. Swift, Kotlin, TypeScript, and Python expose it at module scope. Java and C# place it on the generated module class because those languages do not have module-level values.
The Rust name is converted to the naming convention of each target. API_VERSION becomes apiVersion in Swift, Kotlin, and TypeScript, API_VERSION in Java, ApiVersion in C#, and api_version in Python.
Associated constants
Associated constants are declared inside the same exported impl blocks used for methods and constructors:
- Use
#[data(impl)]for a struct or enum marked with#[data]. - Use
#[export]for a class impl.
Every public constant in the marked impl is generated on its owner type. The constant may use Self or any other supported constant type. The impl marker exports the member, so the individual constant does not need another #[export] attribute.
Color.BLACK uses Self, Color.CHANNEL_COUNT uses a primitive, Mode.DEFAULT aliases an enum variant, and Palette.MAX_COLORS belongs to a Rust-backed class. In every target, the value remains attached to the type that owns it.
Data constants
Every record or enum marked with #[data] can be the value type of a global or associated constant. This includes primitive-only records, encoded records, C-style enums, and data enums. The selected target must already support that data type as a normal return value.
The Color and Mode declarations above are examples of associated data constants. The same data types also work as global constants:
Values such as Color { ... } are constructed in Rust and delivered through a generated accessor. The generated API still exposes an ordinary immutable value.
Supported values
Constants can use the same types as exported function results, including primitives, strings, byte slices, tuples, and types marked with #[data]. Associated constants can use Self for values of their owner type.
