opentalk_types_common/utils/
example_data.rs

1// SPDX-FileCopyrightText: OpenTalk GmbH <mail@opentalk.eu>
2//
3// SPDX-License-Identifier: EUPL-1.2
4
5use opentalk_types_common_identifiers::{
6    asset_file_kind::AssetFileKind, feature_id::FeatureId, module_id::ModuleId,
7};
8
9/// A trait for providing example data of an item.
10pub trait ExampleData {
11    /// Get an example instance of the current datatype.
12    fn example_data() -> Self;
13}
14
15impl ExampleData for FeatureId {
16    fn example_data() -> Self {
17        FeatureId::example_data()
18    }
19}
20
21impl ExampleData for ModuleId {
22    fn example_data() -> Self {
23        ModuleId::example_data()
24    }
25}
26
27impl ExampleData for AssetFileKind {
28    fn example_data() -> Self {
29        AssetFileKind::example_data()
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use opentalk_types_common_identifiers::{
36        asset_file_kind::AssetFileKind, feature_id::FeatureId, module_id::ModuleId,
37    };
38
39    #[test]
40    fn feature_id_example_data() {
41        assert_eq!(
42            FeatureId::example_data(),
43            <FeatureId as super::ExampleData>::example_data()
44        );
45    }
46
47    #[test]
48    fn module_id_example_data() {
49        assert_eq!(
50            ModuleId::example_data(),
51            <ModuleId as super::ExampleData>::example_data()
52        );
53    }
54
55    #[test]
56    fn asset_file_kind_example_data() {
57        assert_eq!(
58            AssetFileKind::example_data(),
59            <AssetFileKind as super::ExampleData>::example_data()
60        );
61    }
62}