Crates.io | fallback-derive |
lib.rs | fallback-derive |
version | 0.1.2 |
source | src |
created_at | 2022-09-10 01:24:15.485343 |
updated_at | 2024-01-13 10:33:26.845982 |
description | A helper library to implement fallback mechaism. |
homepage | |
repository | https://github.com/Berrysoft/fallback |
max_upload_size | |
id | 662190 |
size | 6,821 |
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())));