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