Skip to main content

sl_types/
experience.rs

1//! Experience value types: the property bitfield carried in experience info.
2
3use crate::serde_helpers::impl_bitfield_serde;
4
5/// Experience [`properties`](ExperienceProperties) bit: the experience id is
6/// invalid (a placeholder for an `error_ids` entry the grid could not resolve).
7pub const PROPERTY_INVALID: i32 = 1 << 0;
8/// Experience properties bit: privileged (a Linden-blessed experience).
9pub const PROPERTY_PRIVILEGED: i32 = 1 << 3;
10/// Experience properties bit: grid-wide scope (vs. land-scoped). Mirrors the
11/// viewer's grid-scope notification on a permission request.
12pub const PROPERTY_GRID: i32 = 1 << 4;
13/// Experience properties bit: the experience is private.
14pub const PROPERTY_PRIVATE: i32 = 1 << 5;
15/// Experience properties bit: the experience is disabled.
16pub const PROPERTY_DISABLED: i32 = 1 << 6;
17/// Experience properties bit: the experience is suspended by an admin.
18pub const PROPERTY_SUSPENDED: i32 = 1 << 7;
19
20/// The bitfield of experience-info property flags (the `PROPERTY_*` constants).
21/// Mirrors the viewer's `LLExperienceCache` property bits, which it notes should
22/// track the grid's `experience-api` model.
23#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
24#[expect(
25    clippy::module_name_repetitions,
26    reason = "the type is going to be used outside this module"
27)]
28pub struct ExperienceProperties(pub i32);
29
30impl ExperienceProperties {
31    /// Whether all of the bits in `flag` are set.
32    #[must_use]
33    pub const fn contains(self, flag: i32) -> bool {
34        self.0 & flag == flag
35    }
36
37    /// Whether the experience id is invalid ([`PROPERTY_INVALID`]).
38    #[must_use]
39    pub const fn is_invalid(self) -> bool {
40        self.contains(PROPERTY_INVALID)
41    }
42
43    /// Whether the experience is privileged ([`PROPERTY_PRIVILEGED`]).
44    #[must_use]
45    pub const fn is_privileged(self) -> bool {
46        self.contains(PROPERTY_PRIVILEGED)
47    }
48
49    /// Whether the experience is grid-wide ([`PROPERTY_GRID`]); otherwise it is
50    /// land-scoped.
51    #[must_use]
52    pub const fn is_grid(self) -> bool {
53        self.contains(PROPERTY_GRID)
54    }
55
56    /// Whether the experience is private ([`PROPERTY_PRIVATE`]).
57    #[must_use]
58    pub const fn is_private(self) -> bool {
59        self.contains(PROPERTY_PRIVATE)
60    }
61
62    /// Whether the experience is disabled ([`PROPERTY_DISABLED`]).
63    #[must_use]
64    pub const fn is_disabled(self) -> bool {
65        self.contains(PROPERTY_DISABLED)
66    }
67
68    /// Whether the experience is suspended ([`PROPERTY_SUSPENDED`]).
69    #[must_use]
70    pub const fn is_suspended(self) -> bool {
71        self.contains(PROPERTY_SUSPENDED)
72    }
73}
74
75impl_bitfield_serde!(
76    ExperienceProperties,
77    i32,
78    "INVALID" => PROPERTY_INVALID,
79    "PRIVILEGED" => PROPERTY_PRIVILEGED,
80    "GRID" => PROPERTY_GRID,
81    "PRIVATE" => PROPERTY_PRIVATE,
82    "DISABLED" => PROPERTY_DISABLED,
83    "SUSPENDED" => PROPERTY_SUSPENDED,
84);