https://github.com/berrysoft/fallback
A helper library to implement fallback mechaism.
https://github.com/berrysoft/fallback
Last synced: 9 months ago
JSON representation
A helper library to implement fallback mechaism.
- Host: GitHub
- URL: https://github.com/berrysoft/fallback
- Owner: Berrysoft
- License: mit
- Created: 2022-09-10T01:19:51.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-13T10:31:04.000Z (over 2 years ago)
- Last Synced: 2025-09-28T06:36:55.742Z (9 months ago)
- Language: Rust
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
``` rust
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())));
```