4 releases

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

#437 in Data structures

Download history 24/week @ 2024-04-14 14/week @ 2024-04-21 8/week @ 2024-04-28 1/week @ 2024-05-05 2/week @ 2024-05-12 21/week @ 2024-05-19 39/week @ 2024-05-26 19/week @ 2024-06-02 27/week @ 2024-06-09 11/week @ 2024-06-16 30/week @ 2024-06-23 25/week @ 2024-06-30 12/week @ 2024-07-07 5/week @ 2024-07-14 23/week @ 2024-07-21 70/week @ 2024-07-28

110 downloads per month
Used in 4 crates (2 directly)

MIT license

10KB
141 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())));

lib.rs:

A fallback type.

Fallback type provides functionality to fallback if a value or a part of value doesn't exist.

Dependencies

~260–700KB
~17K SLoC