typechain

Crates.iotypechain
lib.rstypechain
version0.1.0
sourcesrc
created_at2023-06-03 07:26:05.090267
updated_at2023-06-03 07:26:05.090267
descriptionCreate chains of trait objects
homepagehttps://github.com/panthios/typechain
repositoryhttps://github.com/panthios/typechain
max_upload_size
id881414
size19,653
Carlos Kieliszewski (carlosskii)

documentation

https://docs.rs/typechain

README

typechain

This crate provides procedural macros for generating chains of related traits in Rust.

Example

types.rs

use typechain::{chainlink, chain};

chainlink!(Currency => {
  const usd_value: f64;
});

chain!(Fiat => {
  @Currency
  const usd_value: f64;
});

impl Fiat {
  pub fn new(usd_value: f64) -> Self {
    Self { usd_value }
  }
}

chain!(Crypto => {
  @Currency
  const usd_value: f64;
});

impl Crypto {
  pub fn new(usd_value: f64) -> Self {
    Self { usd_value }
  }
}

main.rs

use typechain::use_chains;
mod types;

use types::{Fiat, Crypto};
use_chains![types::Currency];

fn main() {
  let usd = Fiat::new(1.0);
  let btc = Crypto::new(10000.0);

  let currencies: Vec<&Currency> = vec![&usd, &btc];
}
Commit count: 13

cargo fmt