Switch to dark theme

Attributes

Every #[bimetal(...)], by where it goes.

Derives and exports

Item Goes on Does
#[derive(Model)] A Serde type Makes it a model
#[derive(bimetal::Error)] An enum or struct that implements Display Makes it an error
#[bimetal::export] A public function, const, static, or one inherent impl block Exports it

On a model's field

Attribute Does
required The Option<T> field must be present, even as None
literal = <literal> The field must have this boolean, integer or string value
min_length = <n>, max_length = <n> Limits a string's or a list's length
ge = <n>, le = <n> Limits an integer

On an error

Attribute Goes on Does
details A variant, or an error struct Gives its named fields to the hosts as a typed model

On a function or method

Attribute Does
brief Keeps Python's interpreter lock through a synchronous call that never waits. Functions says when
returns(buffer) Returns a numeric Vec<T> as a NumPy array or typed array, also in an Option
returns(arrow) Returns an Arrow value, also in an Option. Needs the arrow or arrow-59 feature

On a parameter

Attribute Does
buffer Takes a numeric slice or Vec<T> as a NumPy array or typed array
arrow Takes an Arrow value by value or by reference, or a RecordBatchStream by value
default = <expression> Lets a caller omit it, and passes the value of an expression of its type

On a resource's method

Attribute Does
constructor Makes it the class constructor, or a factory. Resources says which
skip Keeps it in Rust
enter, exit Implements with and using
next Implements for, and async for when async
getter, setter Implements a property
len, repr, display Implements len() and length, repr(), and str() and toString()
getitem, setitem, delitem Implements value[key], in Python
contains, eq, hash, bool, call Implements in, ==, hash(), bool() and value(...), in Python

A method also takes Rust's #[cfg(feature = "...")], which exports it only with that feature. Resources says which tests a #[cfg] can hold.

Protocols has the signature each one needs.

Serde attributes that matter

Serde decides what crosses, so its attributes shape the contract:

Attribute Effect
rename_all, rename_all_fields, rename Change wire names, which is what TypeScript sees and what a Python model reads
tag = "..." on an enum Makes an internally tagged enum, a discriminated union. Without it, an enum with a variant that carries data is in Serde's default form
transparent on a tuple struct Makes an alias of its field's type
default on a field whose type has a Rust Default Makes it optional. An absent field holds that Default
default = "path" on a field Makes it optional. An absent field holds what the function path returns
skip on a field of an error's details Leaves it out

Bimetal rejects directional renames, such as rename(serialize = "..."), Serde aliases, tag on a struct, and skip_serializing_if on a field with a default function.