Skip to main content

toasty_driver_integration_suite/scenarios/
character_creature.rs

1use crate::prelude::*;
2
3scenario! {
4    #[derive(Debug, toasty::Model)]
5    #[allow(dead_code)]
6    struct Character {
7        #[key]
8        #[auto]
9        id: uuid::Uuid,
10
11        creature: Creature,
12    }
13
14    // Both variants carry a `name`, declared shared via `#[shared(name)]`.
15    // The two variant fields coalesce into a single shared, nullable
16    // `creature_name` column; each variant keeps its own distinct column for
17    // its variant-specific attribute (`creature_profession` / `creature_species`).
18    #[derive(Debug, PartialEq, toasty::Embed)]
19    enum Creature {
20        #[column(variant = 1)]
21        Human {
22            #[shared(name)]
23            name: String,
24            profession: String,
25        },
26        #[column(variant = 2)]
27        Animal {
28            #[shared(name)]
29            name: String,
30            species: String,
31        },
32    }
33
34    async fn setup(test: &mut Test) -> toasty::Db {
35        test.setup_db(models!(Character)).await
36    }
37}