Skip to main content

sl_types/
parcel.rs

1//! Parcel value types: access-list flags and object-return classifications.
2
3use crate::serde_helpers::impl_bitfield_serde;
4
5/// The per-entry classification flags on a parcel access (allow) or ban list.
6///
7/// A bitfield carried by every entry of a parcel access-list reply (alongside
8/// the whole-list scope). On Second Life an entry can be flagged as an
9/// experience allow/block in addition to the plain access/ban list it belongs
10/// to; OpenSim sets the per-entry flags equal to the list's scope. Combine the
11/// constants with [`ParcelAccessFlags::union`].
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
13#[expect(
14    clippy::module_name_repetitions,
15    reason = "the type is going to be used outside this module"
16)]
17pub struct ParcelAccessFlags(pub u32);
18
19impl ParcelAccessFlags {
20    /// No flags set.
21    pub const NONE: Self = Self(0);
22    /// The entry is on the access (allow) list (`AL_ACCESS`, `1 << 0`).
23    pub const ACCESS: Self = Self(1 << 0);
24    /// The entry is on the ban list (`AL_BAN`, `1 << 1`).
25    pub const BAN: Self = Self(1 << 1);
26    /// The entry allows an experience (`AL_ALLOW_EXPERIENCE`, `1 << 3`).
27    pub const ALLOW_EXPERIENCE: Self = Self(1 << 3);
28    /// The entry blocks an experience (`AL_BLOCK_EXPERIENCE`, `1 << 4`).
29    pub const BLOCK_EXPERIENCE: Self = Self(1 << 4);
30
31    /// Combines two sets of access flags.
32    #[must_use]
33    pub const fn union(self, other: Self) -> Self {
34        Self(self.0 | other.0)
35    }
36
37    /// Whether every bit of `other` is set in `self`.
38    #[must_use]
39    pub const fn contains(self, other: Self) -> bool {
40        self.0 & other.0 == other.0
41    }
42
43    /// Whether no flags are set.
44    #[must_use]
45    pub const fn is_empty(self) -> bool {
46        self.0 == 0
47    }
48}
49
50impl_bitfield_serde!(
51    ParcelAccessFlags,
52    u32,
53    "ACCESS" => ParcelAccessFlags::ACCESS.0,
54    "BAN" => ParcelAccessFlags::BAN.0,
55    "ALLOW_EXPERIENCE" => ParcelAccessFlags::ALLOW_EXPERIENCE.0,
56    "BLOCK_EXPERIENCE" => ParcelAccessFlags::BLOCK_EXPERIENCE.0,
57);
58
59/// The kinds of objects to return or select on a parcel, as the `ReturnType` of
60/// a parcel object-return or object-select request. A bitfield: combine the
61/// constants with [`ParcelReturnType::union`].
62#[derive(Debug, Clone, Copy, PartialEq, Eq)]
63#[expect(
64    clippy::module_name_repetitions,
65    reason = "the type is going to be used outside this module"
66)]
67pub struct ParcelReturnType(pub u32);
68
69impl ParcelReturnType {
70    /// No objects (`RT_NONE`).
71    pub const NONE: Self = Self(1 << 0);
72    /// Objects owned by the parcel's owner (`RT_OWNER`).
73    pub const OWNER: Self = Self(1 << 1);
74    /// Objects set to the parcel's group (`RT_GROUP`).
75    pub const GROUP: Self = Self(1 << 2);
76    /// Objects owned by anyone else (`RT_OTHER`).
77    pub const OTHER: Self = Self(1 << 3);
78    /// Only the objects in the supplied id list (`RT_LIST`).
79    pub const LIST: Self = Self(1 << 4);
80    /// Objects that are for sale (`RT_SELL`).
81    pub const SELL: Self = Self(1 << 5);
82
83    /// Combines two sets of return-type bits.
84    #[must_use]
85    pub const fn union(self, other: Self) -> Self {
86        Self(self.0 | other.0)
87    }
88}
89
90impl_bitfield_serde!(
91    ParcelReturnType,
92    u32,
93    "NONE" => ParcelReturnType::NONE.0,
94    "OWNER" => ParcelReturnType::OWNER.0,
95    "GROUP" => ParcelReturnType::GROUP.0,
96    "OTHER" => ParcelReturnType::OTHER.0,
97    "LIST" => ParcelReturnType::LIST.0,
98    "SELL" => ParcelReturnType::SELL.0,
99);