rafia_stpa/
lib.rs

1// *****************************************************************************
2// Copyright (c) 2025 Codethink
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0.
7//
8// This Source Code may also be made available under the following Secondary
9// Licenses when the conditions for such availability set forth in the Eclipse
10// Public License, v. 2.0 are satisfied: GNU General Public License, version 2
11// with the GNU Classpath Exception which is
12// available at https://www.gnu.org/software/classpath/license.html.
13//
14// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15// *****************************************************************************
16
17pub mod stpa;
18#[cfg(feature = "pyo3")]
19pub mod trudag;
20
21/// Defines From<str/String> + Display and Into<WidgetText> for a link type of the form
22/// Unit(Arc<str>)
23#[macro_export]
24macro_rules! define_default_link_type_impls {
25    ($link_type:ident) => {
26        // Allow conversion to $link_type from any type which can become Arc<str>
27        impl<T> ::core::convert::From<T> for $link_type
28        where
29            T: ::core::convert::Into<::std::sync::Arc<str>>,
30        {
31            fn from(value: T) -> Self {
32                Self(value.into())
33            }
34        }
35
36        impl ::core::fmt::Display for $link_type {
37            fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
38                write!(f, "{}", self.0)
39            }
40        }
41
42        #[cfg(feature = "eframe")]
43        #[allow(clippy::from_over_into)]
44        impl Into<::eframe::egui::WidgetText> for $link_type {
45            fn into(self) -> ::eframe::egui::WidgetText {
46                self.0.as_ref().into()
47            }
48        }
49
50        impl AsRef<str> for $link_type {
51            fn as_ref(&self) -> &str {
52                self.0.as_ref()
53            }
54        }
55    };
56}
57
58#[macro_export]
59macro_rules! construct_link_map {
60    (table = $foreign_table:ident, link_type = $link_type:ident) => {
61        construct_link_map!(
62            table = $foreign_table,
63            link_type = $link_type,
64            linked_to = description
65        )
66    };
67    (table = $foreign_table:ident, link_type = $link_type:ident, linked_to = $description:ident) => {
68        $foreign_table
69            .$foreign_table
70            .iter()
71            .map(|item| {
72                (
73                    $link_type::from(item.id.as_str()),
74                    item.$description.clone(),
75                )
76            })
77            .collect::<::indexmap::IndexMap<$link_type, String>>()
78    };
79}