#fallback #helper #derive #mechaism #fallback-spec

macro fallback-derive

A helper library to implement fallback mechaism

3 releases

0.1.2 Jan 13, 2024
0.1.1 Mar 21, 2023
0.1.0 Sep 10, 2022

#24 in #fallback

Download history 19/week @ 2024-07-02 12/week @ 2024-07-09 20/week @ 2024-07-16 37/week @ 2024-07-23 39/week @ 2024-07-30 26/week @ 2024-08-06 22/week @ 2024-08-13 10/week @ 2024-08-20 12/week @ 2024-08-27 3/week @ 2024-09-03 17/week @ 2024-09-10 49/week @ 2024-09-17 52/week @ 2024-09-24 24/week @ 2024-10-01 30/week @ 2024-10-08 28/week @ 2024-10-15

172 downloads per month
Used in 5 crates (via fallback)

MIT license

7KB
108 lines

fallback

This is a helper library to implement fallback mechaism. It contains two Option, and if the "desired" one is None, the "base" one will be chosen.

A trait called FallbackSpec is used to implement field fallback for a struct.

use fallback::*;

#[derive(FallbackSpec)]
struct Foo {
    data1: i32,
    data2: String,
}

let data = Foo {
    data1: 123,
    data2: "Hello".to_string(),
};

let data = Fallback::new(None, Some(data));
let data = data.spec();

assert_eq!(data.data1.unzip(), (None, Some(123)));
assert_eq!(data.data2.unzip(), (None, Some("Hello".to_string())));

Dependencies

~235–680KB
~16K SLoC