Skip to main content

TableRow

Derive Macro TableRow 

Source
#[derive(TableRow)]
{
    // Attributes available to this derive:
    #[yt]
}
Expand description

Derives a YTsaurus table schema from a struct’s fields.

One column per field, in declaration order, named after the field. The Rust type decides the column type, and Option<T> is the only thing that makes a column optional — a bare T is required.

Rustcolumn type
i8 i16 i32 i64int8int64
u8 u16 u32 u64uint8uint64
f32 / f64float / double
boolboolean
String, &str, Cow<str>utf8
Vec<u8>, &[u8]string — YTsaurus strings are arbitrary bytes
YsonValueany
Option<T>T, not required

Anything else is a compile error naming the field: guessing a column type from an unknown Rust type is how a schema comes to disagree with the data. Say what you mean with #[yt(column_type = "…")].

§Attributes

On the struct:

  • #[yt(non_strict)] — let rows carry columns the schema does not mention.
  • #[yt(unique_keys)] — promise no two rows share a key. Requires a key.
  • #[yt(crate_path = "::path::to::ytsaurus_client")] — for a renamed dependency.

On a field:

  • #[yt(key)] — a key column, sorted ascending. Key fields must come first: the cluster refuses a schema whose keys are not a prefix, so the macro refuses it earlier and names the field.
  • #[yt(name = "…")] — the column name, when it differs from the field’s.
  • #[yt(column_type = "…")] — the column type, by its wire name.
  • #[yt(skip)] — not a column at all.

§Example

#[derive(TableRow)]
#[yt(unique_keys)]
struct Session {
    #[yt(key)]
    user_id: i64,
    #[yt(key)]
    started_at: i64,
    #[yt(name = "duration_s")]
    duration: i64,
    #[yt(column_type = "any")]
    details: ytsaurus_client::yson_build::YsonValue,
    #[yt(skip)]
    cached: usize,
}