pytauri_core/ext_mod_impl/lib/
runtime.rs1use std::borrow::Cow;
2
3use pyo3::prelude::*;
4use pyo3_utils::serde::PySerde;
5
6use crate::utils::non_exhaustive_panic;
7
8#[expect(dead_code)] pub(crate) type ConfigFrom = PySerde<tauri::Config>;
13pub(crate) type ConfigInto<'a> = PySerde<Cow<'a, tauri::Config>>;
15
16macro_rules! theme_impl {
17 ($ident:ident => : $($variant:ident),*) => {
18 #[pyclass(frozen, eq, eq_int)]
20 #[derive(PartialEq, Clone, Copy)]
21 #[non_exhaustive]
22 pub enum $ident {
23 $($variant,)*
24 _NonExhaustive,
25 }
26
27 impl From<tauri::Theme> for $ident {
28 fn from(val: tauri::Theme) -> Self {
29 match val {
30 $(tauri::Theme::$variant => $ident::$variant,)*
31 _ => { $ident::_NonExhaustive }
32 }
33 }
34 }
35
36 impl From<$ident> for tauri::Theme {
37 fn from(val: $ident) -> Self {
38 match val {
39 $($ident::$variant => tauri::Theme::$variant,)*
40 $ident::_NonExhaustive => non_exhaustive_panic(),
41 }
42 }
43 }
44 };
45}
46
47theme_impl!(Theme => : Light, Dark);
48
49macro_rules! user_attention_type_impl {
50 ($ident:ident => : $($variant:ident),*) => {
51 #[pyclass(frozen, eq, eq_int)]
53 #[derive(PartialEq, Clone, Copy)]
54 #[non_exhaustive]
55 pub enum $ident {
56 $($variant,)*
57 }
58
59 impl From<tauri::UserAttentionType> for $ident {
60 fn from(val: tauri::UserAttentionType) -> Self {
61 match val {
62 $(tauri::UserAttentionType::$variant => $ident::$variant,)*
63 }
64 }
65 }
66
67 impl From<$ident> for tauri::UserAttentionType {
68 fn from(val: $ident) -> Self {
69 match val {
70 $($ident::$variant => tauri::UserAttentionType::$variant,)*
71 }
72 }
73 }
74 };
75}
76
77user_attention_type_impl!(UserAttentionType => : Critical, Informational);
78
79macro_rules! cursor_icon_impl {
80 ($ident:ident => : $($variant:ident),*) => {
81 #[pyclass(frozen, eq, eq_int)]
83 #[derive(PartialEq, Clone, Copy)]
84 #[non_exhaustive]
85 pub enum $ident {
86 $($variant,)*
87 _NonExhaustive,
88 }
89
90 impl From<tauri::CursorIcon> for $ident {
91 fn from(val: tauri::CursorIcon) -> Self {
92 match val {
93 $(tauri::CursorIcon::$variant => $ident::$variant,)*
94 _ => { $ident::_NonExhaustive }
95 }
96 }
97 }
98
99 impl From<$ident> for tauri::CursorIcon {
100 fn from(val: $ident) -> Self {
101 match val {
102 $($ident::$variant => tauri::CursorIcon::$variant,)*
103 $ident::_NonExhaustive => non_exhaustive_panic(),
104 }
105 }
106 }
107 };
108}
109
110cursor_icon_impl!(
111 CursorIcon => :
112 Default,
113 Crosshair,
114 Hand,
115 Arrow,
116 Move,
117 Text,
118 Wait,
119 Help,
120 Progress,
121 NotAllowed,
122 ContextMenu,
123 Cell,
124 VerticalText,
125 Alias,
126 Copy,
127 NoDrop,
128 Grab,
129 Grabbing,
130 AllScroll,
131 ZoomIn,
132 ZoomOut,
133 EResize,
134 NResize,
135 NeResize,
136 NwResize,
137 SResize,
138 SeResize,
139 SwResize,
140 WResize,
141 EwResize,
142 NsResize,
143 NeswResize,
144 NwseResize,
145 ColResize,
146 RowResize
147);