#serde #serialization #convert #deserialize #declaration #type #avdl

avdl-serde-code-generator

A library to convert avdl declarations into Rust types with serde support

3 unstable releases

0.2.0 Feb 28, 2020
0.1.1 Sep 25, 2019
0.1.0 Sep 8, 2019

#1562 in Encoding


Used in 5 crates (via keybase-protocol)

Apache-2.0 OR MIT

35KB
1K SLoC

AVDL Rust Code Generator (With serde support)

A library to convert avdl declarations into Rust types with serde support.

Turns this:

record Thread {
  @jsonkey("messages")
  array<Message> messages;
  @jsonkey("pagination")
  union { null, Pagination } pagination;
  @jsonkey("offline")
  boolean offline;
  @jsonkey("identify_failures")
  array<keybase1.TLFIdentifyFailure> identifyFailures;
  @jsonkey("ratelimits")
  array<RateLimitRes> rateLimits;
}

into this:

#[derive(Serialize, Deserialize, Debug)]
pub struct Thread {
  #[serde(rename = "messages")]
  #[serde(default)]
  pub messages: Option<Vec<Message>>,
  #[serde(rename = "pagination")]
  pub pagination: Option<Pagination>,
  #[serde(rename = "offline")]
  #[serde(default)]
  pub offline: Option<bool>,
  #[serde(rename = "identify_failures")]
  #[serde(default)]
  pub identifyFailures: Option<Vec<keybase1::TLFIdentifyFailure>>,
  #[serde(rename = "ratelimits")]
  #[serde(default)]
  pub rateLimits: Option<Vec<RateLimitRes>>,
}

Why?

This is mostly to export Keybase's types defined in their protocol for use in Rust.

Usage

look at to_rust::build_rust_code_from_avdl.

Dependencies

~4–6MB
~111K SLoC