Skip to main content

sl_types/
friend.rs

1//! Friendship-related value types.
2
3use crate::serde_helpers::impl_bitfield_serde;
4
5/// The rights one party grants the other in a Second Life friendship: a
6/// bitfield shared by the login `buddy-list`, `GrantUserRights`, and
7/// `ChangeUserRights`. The flag values match the viewer's `RIGHTS_*`/`GRANT_*`
8/// constants.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
10#[expect(
11    clippy::module_name_repetitions,
12    reason = "the type is going to be used outside this module"
13)]
14pub struct FriendRights(pub i32);
15
16impl FriendRights {
17    /// The other party may see when this party is online (`GRANT_ONLINE_STATUS`).
18    pub const CAN_SEE_ONLINE: i32 = 1 << 0;
19    /// The other party may see this party's location on the world map
20    /// (`GRANT_MAP_LOCATION`).
21    pub const CAN_SEE_ON_MAP: i32 = 1 << 1;
22    /// The other party may modify this party's objects (`GRANT_MODIFY_OBJECTS`).
23    pub const CAN_MODIFY_OBJECTS: i32 = 1 << 2;
24
25    /// Whether the see-online bit is set.
26    #[must_use]
27    pub const fn can_see_online(self) -> bool {
28        self.0 & Self::CAN_SEE_ONLINE != 0
29    }
30
31    /// Whether the see-on-map bit is set.
32    #[must_use]
33    pub const fn can_see_on_map(self) -> bool {
34        self.0 & Self::CAN_SEE_ON_MAP != 0
35    }
36
37    /// Whether the modify-objects bit is set.
38    #[must_use]
39    pub const fn can_modify_objects(self) -> bool {
40        self.0 & Self::CAN_MODIFY_OBJECTS != 0
41    }
42}
43
44impl_bitfield_serde!(
45    FriendRights,
46    i32,
47    "CAN_SEE_ONLINE" => FriendRights::CAN_SEE_ONLINE,
48    "CAN_SEE_ON_MAP" => FriendRights::CAN_SEE_ON_MAP,
49    "CAN_MODIFY_OBJECTS" => FriendRights::CAN_MODIFY_OBJECTS,
50);