atspi_common/role.rs
1use serde::{Deserialize, Serialize};
2use zvariant::Type;
3
4use crate::AtspiError;
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type, Hash)]
7/// An accessible object role.
8///
9/// To think of it in terms of HTML, any semantic element likely has a corollary in this enum.
10/// For example: `<button>`, `<input>`, `<form>` or `<h4>`.
11/// Non-semantic elements like `<span>`, `<div>` and `<b>` will not be represented here, and this information is not passed through via the atspi library.
12/// TODO: add examples for GTK/Qt libraries in addition to HTML examples.
13#[repr(u32)]
14pub enum Role {
15 /// A role indicating an error condition, such as uninitialized Role data, or an error deserializing.
16 Invalid,
17 /// Object is a label indicating the keyboard accelerators for the parent.
18 AcceleratorLabel,
19 /// Object is used to alert the user about something.
20 Alert,
21 /// Object contains a dynamic or moving image of some kind.
22 Animation,
23 /// Object is a 2d directional indicator.
24 Arrow,
25 /// Object contains one or more dates, usually arranged into a 2d list.
26 Calendar,
27 /// Object that can be drawn into and is used to trap events.
28 Canvas,
29 /// A choice that can be checked or unchecked and provides a separate indicator for the current state.
30 CheckBox,
31 /// A menu item that behaves like a check box. See [`Self::CheckBox`].
32 CheckMenuItem,
33 /// A specialized dialog that lets the user choose a color.
34 ColorChooser,
35 /// The header for a column of data.
36 ColumnHeader,
37 /// A list of choices the user can select from.
38 ComboBox,
39 /// An object which allows entry of a date.
40 DateEditor,
41 /// An inconifed internal frame within a [`Role::DesktopFrame`].
42 DesktopIcon,
43 /// A pane that supports internal frames and iconified versions of those internal frames.
44 DesktopFrame,
45 /// An object that allows a value to be changed via rotating a visual element, or which displays a value via such a rotating element.
46 Dial,
47 /// A top level window with title bar and a border.
48 Dialog,
49 /// A pane that allows the user to navigate through and select the contents of a directory.
50 DirectoryPane,
51 /// An object used for drawing custom user interface elements.
52 DrawingArea,
53 /// A specialized dialog that displays the files in the directory and lets the user select a file, browse a different directory, or specify a filename.
54 FileChooser,
55 /// A object that fills up space in a user interface.
56 Filler,
57 /// Don't use, reserved for future use.
58 FocusTraversable,
59 /// Allows selection of a display font.
60 FontChooser,
61 /// A top level window with a title bar, border, menubar, etc.
62 Frame,
63 /// A pane that is guaranteed to be painted on top of all panes beneath it.
64 GlassPane,
65 /// A document container for HTML, whose children represent the document content.
66 HTMLContainer,
67 /// A small fixed size picture, typically used to decorate components.
68 Icon,
69 /// An image, typically static.
70 Image,
71 /// A frame-like object that is clipped by a desktop pane.
72 InternalFrame,
73 /// An object used to present an icon or short string in an interface.
74 Label,
75 /// A specialized pane that allows its children to be drawn in layers, providing a form of stacking order.
76 LayeredPane,
77 /// An object that presents a list of objects to the user and * allows the user to select one or more of them.
78 List,
79 /// An object that represents an element of a list.
80 ListItem,
81 /// An object usually found inside a menu bar that contains a list of actions the user can choose from.
82 Menu,
83 /// An object usually drawn at the top of the primary dialog box of an application that contains a list of menus the user can choose from.
84 MenuBar,
85 /// An object usually contained in a menu that presents an action the user can choose.
86 MenuItem,
87 /// A specialized pane whose primary use is inside a dialog.
88 OptionPane,
89 /// An object that is a child of a page tab list.
90 PageTab,
91 /// An object that presents a series of panels (or page tabs), one at a time,through some mechanism provided by the object.
92 PageTabList,
93 /// A generic container that is often used to group objects.
94 Panel,
95 /// A text object uses for passwords, or other places where the text content is not shown visibly to the user.
96 PasswordText,
97 /// A temporary window that is usually used to offer the user a list of choices, and then hides when the user selects one of those choices.
98 PopupMenu,
99 /// An object used to indicate how much of a task has been completed.
100 ProgressBar,
101 /// An object the user can manipulate to tell the application to do something.
102 Button,
103 /// A specialized check box that will cause other radio buttons in the same group to become unchecked when this one is checked.
104 RadioButton,
105 /// Object is both a menu item and a "radio button". See [`Self::RadioButton`].
106 RadioMenuItem,
107 /// A specialized pane that has a glass pane and a layered pane as its children.
108 RootPane,
109 /// The header for a row of data.
110 RowHeader,
111 /// An object usually used to allow a user to incrementally view a large amount of data by moving the bounds of a viewport along a one-dimensional axis.
112 ScrollBar,
113 /// A scroll pane: the pane in which the scrollable content is contained within.
114 /// An object that allows a user to incrementally view a large amount of information.
115 /// [`Self::ScrollPane`] objects are usually accompanied by [`Self::ScrollBar`] controllers,
116 /// on which the [`crate::RelationType::ControllerFor`] and [`crate::RelationType::ControlledBy`] reciprocal relations are set.
117 ScrollPane,
118 /// An object usually contained in a menu to provide a visible and logical separation of the contents in a menu.
119 Separator,
120 /// An object that allows the user to select from a bounded range.
121 /// Unlike [`Self::ScrollBar`], [`Self::Slider`] objects need not control 'viewport'-like objects.
122 Slider,
123 /// An object which allows one of a set of choices to be selected, and which displays the current choice.
124 SpinButton,
125 /// A specialized panel that presents two other panels at the same time.
126 SplitPane,
127 /// Object displays non-quantitative status information (c.f. [`Self::ProgressBar`])
128 StatusBar,
129 /// An object used to represent information in terms of rows and columns.
130 Table,
131 /// A 'cell' or discrete child within a Table.
132 /// Note: Table cells need not have [`Self::TableCell`], other [`crate::Role`] values are valid as well.
133 TableCell,
134 /// An object which labels a particular column in an [`Self::Table`].
135 TableColumnHeader,
136 /// An object which labels a particular row in a [`Self::Table`].
137 /// `TableProxy` rows and columns may also be labelled via the
138 /// [`crate::RelationType::LabelFor`]/[`crate::RelationType::LabelledBy`] relationships.
139 /// See: `AccessibleProxy::get_relation_type`.
140 TableRowHeader,
141 /// Object allows menu to be removed from menubar and shown in its own window.
142 TearoffMenuItem,
143 /// An object that emulates a terminal.
144 Terminal,
145 /// An interactive widget that supports multiple lines of text and optionally accepts user input,
146 /// but whose purpose is not to solicit user input.
147 /// Thus [`Self::Text`] is appropriate for the text view in a plain text editor but inappropriate for an input field in a dialog box or web form.
148 /// For widgets whose purpose is to solicit input from the user, see [`Self::Entry`] and [`Self::PasswordText`].
149 /// For generic objects which display a brief amount of textual information, see [`Self::Static`].
150 Text,
151 /// A specialized push button that can be checked or unchecked, but does not provide a separate indicator for the current state.
152 ToggleButton,
153 /// A bar or palette usually composed of push buttons or toggle buttons.
154 ToolBar,
155 /// An object that provides information about another object.
156 ToolTip,
157 /// An object used to repsent hierarchical information to the user.
158 Tree,
159 /// An object that presents both tabular and hierarchical info to the user.
160 TreeTable,
161 /// When the role cannot be accurately reported, this role will be set.
162 Unknown,
163 /// An object usually used in a scroll pane, or to otherwise clip a larger object or content renderer to a specific onscreen viewport.
164 Viewport,
165 /// A top level window with no title or border.
166 Window,
167 /// means that the role for this item is known, but not included in the core enumeration.
168 Extended,
169 /// An object that serves as a document header.
170 Header,
171 /// An object that serves as a document footer.
172 Footer,
173 /// An object which is contains a single paragraph of text content. See also [`Self::Text`].
174 Paragraph,
175 /// An object which describes margins and tab stops, etc. for text objects which it controls (should have [`crate::RelationType::ControllerFor`] relation to such).
176 Ruler,
177 /// An object corresponding to the toplevel accessible of an application, which may contain [`Self::Frame`] objects or other accessible objects.
178 /// Children of objects with the [`Self::DesktopFrame`] role are generally [`Self::Application`] objects.
179 Application,
180 /// The object is a dialog or list containing items for insertion into an entry widget, for instance a list of words for completion of a text entry.
181 Autocomplete,
182 /// The object is an editable text object in a toolbar.
183 Editbar,
184 /// The object is an embedded component container.
185 /// This role is a "grouping" hint that the contained objects share a context which is different from the container in which this accessible is embedded.
186 /// In particular, it is used for some kinds of document embedding, and for embedding of out-of-process component, "panel applets", etc.
187 Embedded,
188 /// The object is a component whose textual content may be entered or modified by the user, provided [`crate::State::Editable`] is present.
189 /// A readonly [`Self::Entry`] object (i.e. where [`crate::State::Editable`] is not present) implies a read-only 'text field' in a form, as opposed to a title, label, or caption.
190 Entry,
191 /// The object is a graphical depiction of quantitative data.
192 /// It may contain multiple subelements whose attributes and/or description may be queried to obtain both the quantitative data and information about how the data is being presented.
193 /// The [`crate::RelationType::LabelledBy`] relation is particularly important in interpreting objects of this type, as is the accessible description property.
194 /// See [`Self::Caption`].
195 CHART,
196 /// The object contains descriptive information, usually textual, about another user interface element such as a table, chart, or image.
197 Caption,
198 /// The object is a visual frame or container which
199 /// contains a view of document content. [`Self::DocumentFrame`]s may occur within
200 /// another `DocumentProxy` instance, in which case the second document may be
201 /// said to be embedded in the containing instance.
202 /// HTML frames are often [`Self::DocumentFrame`]: Either this object, or a singleton descendant,
203 /// should implement the [`crate::Interface::Document`] interface.
204 DocumentFrame,
205 /// Heading: this is a heading with a level (usually 1-6). This is represented by `<h1>` through `<h6>` in HTML.
206 /// The object serves as a heading for content which follows it in a document.
207 /// The 'heading level' of the heading, if available, may be obtained by querying the object's attributes.
208 Heading,
209 /// The object is a containing instance which encapsulates a page of information.
210 /// [`Self::Page`] is used in documents and content which support a paginated navigation model.
211 Page,
212 /// The object is a containing instance of document content which constitutes a particular 'logical' section of the document.
213 /// The type of content within a section, and the nature of the section division itself, may be obtained by querying the object's attributes.
214 /// Sections may be nested.
215 Section,
216 /// The object is redundant with another object in the hierarchy, and is exposed for purely technical reasons.
217 /// Objects of this role should be ignored by clients, if they are encountered at all.
218 RedundantObject,
219 /// The object is a containing instance of document content which has within it components with which the user can interact in order to input information;
220 /// i.e. the object is a container for pushbuttons, comboboxes, text input fields, and other 'GUI' components.
221 /// [`Self::Form`] should not, in general, be used for toplevel GUI containers or dialogs, but should be reserved for 'GUI' containers which occur within document content, for instance within Web documents, presentations, or text documents.
222 /// Unlike other GUI containers and dialogs which occur inside application instances, [`Self::Form`] containers' components are associated with the current document, rather than the current foreground application or viewer instance.
223 Form,
224 /// The object is a hypertext anchor, i.e. a "link" in a hypertext document.
225 /// Such objects are distinct from 'inline' content which may also use the [`crate::Interface::Hypertext`]/[`crate::Interface::Hyperlink`] interfaces to indicate the range/location within a text object where an inline or embedded object lies.
226 Link,
227 /// The object is a window or similar viewport which is used to allow composition or input of a 'complex character', in other words it is an "input method window".
228 InputMethodWindow,
229 /// A row in a table.
230 TableRow,
231 /// An object that represents an element of a tree.
232 TreeItem,
233 /// A document frame which contains a spreadsheet.
234 DocumentSpreadsheet,
235 /// A document frame which contains a presentation or slide content.
236 DocumentPresentation,
237 /// A document frame which contains textual content, such as found in a word processing application.
238 DocumentText,
239 /// A document frame which contains HTML or other markup suitable for display in a web browser.
240 DocumentWeb,
241 /// A document frame which contains email content to be displayed or composed either in plain text or HTML.
242 DocumentEmail,
243 /// An object found within a document and designed to present a comment, note, or other annotation.
244 /// In some cases, this object might not be visible until activated.
245 Comment,
246 /// A non-collapsible list of choices the user can select from.
247 ListBox,
248 /// A group of related widgets. This group typically has a label.
249 Grouping,
250 /// An image map object. Usually a graphic with multiple hotspots, where each hotspot can be activated resulting in the loading of another document or section of a document.
251 ImageMap,
252 /// A transitory object designed to present a message to the user, typically at the desktop level rather than inside a particular application.
253 Notification,
254 /// An object designed to present a message to the user within an existing window.
255 InfoBar,
256 /// A bar that serves as a level indicator to, for instance, show the strength of a password or the state of a battery.
257 LevelBar,
258 /// A bar that serves as the title of a window or a dialog.
259 TitleBar,
260 /// An object which contains a text section that is quoted from another source.
261 BlockQuote,
262 /// An object which represents an audio element.
263 Audio,
264 /// An object which represents a video element.
265 Video,
266 /// A definition of a term or concept.
267 Definition,
268 /// A section of a page that consists of a composition that forms an independent part of a document, page, or site.
269 /// Examples: A blog entry, a news story, a forum post.
270 Article,
271 /// A region of a web page intended as a navigational landmark. This is designed to allow Assistive Technologies to provide quick navigation among key regions within a document.
272 Landmark,
273 /// A text widget or container holding log content, such as chat history and error logs. In this role there is a relationship between the arrival of new items in the log and the reading order.
274 /// The log contains a meaningful sequence and new information is added only to the end of the log, not at arbitrary points.
275 Log,
276 /// A container where non-essential information changes frequently.
277 /// Common usages of marquee include stock tickers and ad banners.
278 /// The primary difference between a marquee and a log is that logs usually have a meaningful order or sequence of important content changes.
279 Marquee,
280 /// A text widget or container that holds a mathematical expression.
281 Math,
282 /// A rating system, generally out of five stars, but it does not need to be that way. There is no tag nor role for this in HTML, however.
283 /// A widget whose purpose is to display a rating, such as the number of stars associated with a song in a media player.
284 /// Objects of this role should also implement [`crate::Interface::Value`].
285 Rating,
286 /// An object containing a numerical counter which indicates an amount of elapsed time from a start point, or the time remaining until an end point.
287 Timer,
288 /// A generic non-container object whose purpose is to display a brief amount of information to the user and whose role is known by the implementor but lacks semantic value for the user.
289 /// Examples in which [`Self::Static`] is appropriate include the message displayed in a message box and an image used as an alternative means to display text.
290 /// [`Self::Static`] should not be applied to widgets which are traditionally interactive, objects which display a significant amount of content, or any object which has an accessible relation pointing to another object.
291 /// The displayed information, as a general rule, should be exposed through the accessible name of the object.
292 /// For labels which describe another widget, see [`Self::Label`].
293 /// For text views, see [`Self::Text`].
294 /// For generic containers, see [`Self::Panel`]. For objects whose role is not known by the implementor, see [`Self::Unknown`].
295 Static,
296 /// An object that represents a mathematical fraction.
297 MathFraction,
298 /// An object that represents a mathematical expression displayed with a radical.
299 MathRoot,
300 /// An object that contains text that is displayed as a subscript.
301 Subscript,
302 /// An object that contains text that is displayed as a superscript.
303 Superscript,
304 /// An object that represents a list of term-value groups.
305 /// A term-value group represents an individual description and consist of one or more names ([`Self::DescriptionTerm`]) followed by one or more values ([`Self::DescriptionValue`]).
306 /// For each list, there should not be more than one group with the same term name.
307 DescriptionList,
308 /// An object that represents a term or phrase with a corresponding definition.
309 DescriptionTerm,
310 /// An object that represents the description, definition, or value of a term.
311 DescriptionValue,
312 /// An object that contains the text of a footnote.
313 Footnote,
314 /// Content previously deleted or proposed to be deleted, e.g. in revision history or a content view providing suggestions from reviewers.
315 ContentDeletion,
316 /// Content previously inserted or proposed to be inserted, e.g. in revision history or a content view providing suggestions from reviewers.
317 ContentInsertion,
318 /// A run of content that is marked or highlighted, such as for reference purposes, or to call it out as having a special purpose.
319 /// If the marked content has an associated section in the document elaborating on the reason for the mark, then [`crate::RelationType::Details`] should be used on the mark to point to that associated section.
320 /// In addition, the reciprocal relation [`crate::RelationType::DetailsFor`] should be used on the associated content section to point back to the mark.
321 Mark,
322 /// A container for content that is called out as a proposed change from the current version of the document, such as by a reviewer of the content.
323 /// An object with this role should include children with [`Self::ContentDeletion`] and/or [`Self::ContentInsertion`], in any order, to indicate what the actual change is.
324 Suggestion,
325 /// A specialized push button to open a menu.
326 PushButtonMenu,
327}
328
329impl TryFrom<u32> for Role {
330 type Error = AtspiError;
331
332 #[allow(clippy::too_many_lines)]
333 fn try_from(value: u32) -> Result<Self, Self::Error> {
334 #[allow(clippy::enum_glob_use)]
335 use Role::*;
336 let res = match value {
337 0 => Invalid,
338 1 => AcceleratorLabel,
339 2 => Alert,
340 3 => Animation,
341 4 => Arrow,
342 5 => Calendar,
343 6 => Canvas,
344 7 => CheckBox,
345 8 => CheckMenuItem,
346 9 => ColorChooser,
347 10 => ColumnHeader,
348 11 => ComboBox,
349 12 => DateEditor,
350 13 => DesktopIcon,
351 14 => DesktopFrame,
352 15 => Dial,
353 16 => Dialog,
354 17 => DirectoryPane,
355 18 => DrawingArea,
356 19 => FileChooser,
357 20 => Filler,
358 21 => FocusTraversable,
359 22 => FontChooser,
360 23 => Frame,
361 24 => GlassPane,
362 25 => HTMLContainer,
363 26 => Icon,
364 27 => Image,
365 28 => InternalFrame,
366 29 => Label,
367 30 => LayeredPane,
368 31 => List,
369 32 => ListItem,
370 33 => Menu,
371 34 => MenuBar,
372 35 => MenuItem,
373 36 => OptionPane,
374 37 => PageTab,
375 38 => PageTabList,
376 39 => Panel,
377 40 => PasswordText,
378 41 => PopupMenu,
379 42 => ProgressBar,
380 43 => Button,
381 44 => RadioButton,
382 45 => RadioMenuItem,
383 46 => RootPane,
384 47 => RowHeader,
385 48 => ScrollBar,
386 49 => ScrollPane,
387 50 => Separator,
388 51 => Slider,
389 52 => SpinButton,
390 53 => SplitPane,
391 54 => StatusBar,
392 55 => Table,
393 56 => TableCell,
394 57 => TableColumnHeader,
395 58 => TableRowHeader,
396 59 => TearoffMenuItem,
397 60 => Terminal,
398 61 => Text,
399 62 => ToggleButton,
400 63 => ToolBar,
401 64 => ToolTip,
402 65 => Tree,
403 66 => TreeTable,
404 67 => Unknown,
405 68 => Viewport,
406 69 => Window,
407 70 => Extended,
408 71 => Header,
409 72 => Footer,
410 73 => Paragraph,
411 74 => Ruler,
412 75 => Application,
413 76 => Autocomplete,
414 77 => Editbar,
415 78 => Embedded,
416 79 => Entry,
417 80 => CHART,
418 81 => Caption,
419 82 => DocumentFrame,
420 83 => Heading,
421 84 => Page,
422 85 => Section,
423 86 => RedundantObject,
424 87 => Form,
425 88 => Link,
426 89 => InputMethodWindow,
427 90 => TableRow,
428 91 => TreeItem,
429 92 => DocumentSpreadsheet,
430 93 => DocumentPresentation,
431 94 => DocumentText,
432 95 => DocumentWeb,
433 96 => DocumentEmail,
434 97 => Comment,
435 98 => ListBox,
436 99 => Grouping,
437 100 => ImageMap,
438 101 => Notification,
439 102 => InfoBar,
440 103 => LevelBar,
441 104 => TitleBar,
442 105 => BlockQuote,
443 106 => Audio,
444 107 => Video,
445 108 => Definition,
446 109 => Article,
447 110 => Landmark,
448 111 => Log,
449 112 => Marquee,
450 113 => Math,
451 114 => Rating,
452 115 => Timer,
453 116 => Static,
454 117 => MathFraction,
455 118 => MathRoot,
456 119 => Subscript,
457 120 => Superscript,
458 121 => DescriptionList,
459 122 => DescriptionTerm,
460 123 => DescriptionValue,
461 124 => Footnote,
462 125 => ContentDeletion,
463 126 => ContentInsertion,
464 127 => Mark,
465 128 => Suggestion,
466 129 => PushButtonMenu,
467 _ => return Err(AtspiError::UnknownRole(value)),
468 };
469 Ok(res)
470 }
471}
472
473const ROLE_NAMES: &[&str] = &[
474 "invalid",
475 "accelerator label",
476 "alert",
477 "animation",
478 "arrow",
479 "calendar",
480 "canvas",
481 "check box",
482 "check menu item",
483 "color chooser",
484 "column header",
485 "combo box",
486 "date editor",
487 "desktop icon",
488 "desktop frame",
489 "dial",
490 "dialog",
491 "directory pane",
492 "drawing area",
493 "file chooser",
494 "filler",
495 "focus traversable",
496 "font chooser",
497 "frame",
498 "glass pane",
499 "html container",
500 "icon",
501 "image",
502 "internal frame",
503 "label",
504 "layered pane",
505 "list",
506 "list item",
507 "menu",
508 "menu bar",
509 "menu item",
510 "option pane",
511 "page tab",
512 "page tab list",
513 "panel",
514 "password text",
515 "popup menu",
516 "progress bar",
517 "button",
518 "radio button",
519 "radio menu item",
520 "root pane",
521 "row header",
522 "scroll bar",
523 "scroll pane",
524 "separator",
525 "slider",
526 "spin button",
527 "split pane",
528 "status bar",
529 "table",
530 "table cell",
531 "table column header",
532 "table row header",
533 "tearoff menu item",
534 "terminal",
535 "text",
536 "toggle button",
537 "tool bar",
538 "tool tip",
539 "tree",
540 "tree table",
541 "unknown",
542 "viewport",
543 "window",
544 "extended",
545 "header",
546 "footer",
547 "paragraph",
548 "ruler",
549 "application",
550 "autocomplete",
551 "editbar",
552 "embedded",
553 "entry",
554 "chart",
555 "caption",
556 "document frame",
557 "heading",
558 "page",
559 "section",
560 "redundant object",
561 "form",
562 "link",
563 "input method window",
564 "table row",
565 "tree item",
566 "document spreadsheet",
567 "document presentation",
568 "document text",
569 "document web",
570 "document email",
571 "comment",
572 "list box",
573 "grouping",
574 "image map",
575 "notification",
576 "info bar",
577 "level bar",
578 "title bar",
579 "block quote",
580 "audio",
581 "video",
582 "definition",
583 "article",
584 "landmark",
585 "log",
586 "marquee",
587 "math",
588 "rating",
589 "timer",
590 "static",
591 "math fraction",
592 "math root",
593 "subscript",
594 "superscript",
595 "description list",
596 "description term",
597 "description value",
598 "footnote",
599 "content deletion",
600 "content insertion",
601 "mark",
602 "suggestion",
603 "push button menu",
604];
605
606impl Role {
607 /// Get a readable, English name from the role.
608 #[must_use]
609 pub fn name(&self) -> &'static str {
610 ROLE_NAMES[*self as usize]
611 }
612}
613
614impl std::fmt::Display for Role {
615 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
616 f.write_str(self.name())
617 }
618}
619
620#[cfg(test)]
621pub mod tests {
622 use super::Role;
623 use zvariant::serialized::Context;
624 use zvariant::{to_bytes, LE};
625
626 const HIGHEST_ROLE_VALUE: u32 = 129;
627
628 #[test]
629 fn test_serialization_matches_from_impl() {
630 let ctxt = Context::new_dbus(LE, 0);
631
632 for role_num in 1..=HIGHEST_ROLE_VALUE {
633 let from_role = Role::try_from(role_num)
634 .unwrap_or_else(|_| panic!("Unable to convert {role_num} into Role"));
635 let encoded = to_bytes(ctxt, &from_role)
636 .unwrap_or_else(|_| panic!("Unable to encode {from_role}"));
637 println!("ENCODED: {encoded:?}");
638
639 let (zbus_role, _) = encoded
640 .deserialize()
641 .unwrap_or_else(|_| panic!("Unable to decode {encoded:?}"));
642
643 assert_eq!(from_role, zbus_role, "The serde `Data::deserialize` and `From<u32>` impls produced different results. The number used was {role_num}, it produced a Role of {from_role}, but the from_slice(...) implementation produced {zbus_role}");
644 assert_eq!(
645 from_role as u32, role_num,
646 "The role number {role_num} does not match the representation of the role {}",
647 from_role as u32
648 );
649 }
650 }
651}