tablo_core/resource/action/places.rs
1//! [`Places`]: where an action's button renders.
2
3/// Where an [`Action`](super::Action)'s button renders: [`Action::PLACES`](super::Action::PLACES).
4///
5/// ```rust
6/// # use tablo_core::Places;
7/// // On the detail page and the bulk bar, not on each row or the edit page.
8/// const PLACES: Places = Places::DETAIL.with(Places::BULK);
9/// assert!(PLACES.contains(Places::BULK));
10/// assert!(!PLACES.contains(Places::ROW));
11/// ```
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub struct Places(u8);
14
15impl Places {
16 /// A button in each table row, the related tables' included.
17 pub const ROW: Self = Self(1);
18 /// A button in the detail page's header.
19 pub const DETAIL: Self = Self(1 << 1);
20 /// A button in the edit page's header. It posts a form of its own, so it runs on the record
21 /// as stored, and a change typed into the edit form and not saved is lost.
22 pub const EDIT: Self = Self(1 << 2);
23 /// An entry in the bulk bar, run on the selection.
24 pub const BULK: Self = Self(1 << 3);
25 /// Every place that shows one record: [`ROW`](Self::ROW), [`DETAIL`](Self::DETAIL) and
26 /// [`EDIT`](Self::EDIT).
27 pub const RECORD: Self = Self(Self::ROW.0 | Self::DETAIL.0 | Self::EDIT.0);
28 /// Every place.
29 pub const ALL: Self = Self(Self::RECORD.0 | Self::BULK.0);
30
31 /// These places and `other`'s.
32 #[must_use]
33 pub const fn with(self, other: Self) -> Self {
34 Self(self.0 | other.0)
35 }
36
37 /// Whether every place of `other` is one of these.
38 #[must_use]
39 pub const fn contains(self, other: Self) -> bool {
40 self.0 & other.0 == other.0
41 }
42
43 /// Whether any place of `other` is one of these.
44 #[must_use]
45 pub const fn intersects(self, other: Self) -> bool {
46 self.0 & other.0 != 0
47 }
48}