File: ast_serde.rs

package info (click to toggle)
rust-swc-core 22.2.1~ds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 62,436 kB
  • sloc: javascript: 853; xml: 538; sh: 307; makefile: 35; python: 5
file content (24 lines) | stat: -rw-r--r-- 459 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use serde_json::from_str;
use swc_common::ast_serde;

#[ast_serde]
#[derive(Debug, PartialEq, Eq)]
pub enum Ambiguous {
    #[tag("A")]
    A(A),
    #[tag("B")]
    B(B),
}
#[ast_serde("B")]
#[derive(Debug, PartialEq, Eq)]
pub struct A {}

#[ast_serde("B")]
#[derive(Debug, PartialEq, Eq)]
pub struct B {}

#[test]
fn deserialize() {
    assert_eq!(A {}, from_str(r#"{"type": "A"}"#).unwrap());
    assert_eq!(B {}, from_str(r#"{"type": "B"}"#).unwrap());
}