request/request.rs
1use superstruct::superstruct;
2
3#[superstruct(variants(V1, V2))]
4pub struct Request {
5 pub start: u16,
6 #[superstruct(only(V2))]
7 pub end: u16,
8}
9
10#[cfg_attr(test, test)]
11fn main() {
12 let r1 = Request::V1(RequestV1 { start: 0 });
13 let r2 = Request::V2(RequestV2 { start: 0, end: 10 });
14
15 assert_eq!(r1.start(), r2.start());
16 assert_eq!(r1.end(), Err(()));
17 assert_eq!(r2.end(), Ok(&10));
18}