1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use serde::{Deserialize, Serialize};

/// A unique identifier for a content item.
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
pub struct ContentId {
    /// The user ID of the content item.
    pub user_id: i32,
    /// The sub ID of the content item.
    pub sub_id: i32,
}

impl Eq for ContentId {}

impl std::hash::Hash for ContentId {
    #[inline(always)]
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.user_id.hash(state);
        self.sub_id.hash(state);
    }
}

#[cfg(feature = "ffi")]
mod ffi {
    use lotus_script_sys::{FfiObject, FromFfi};

    impl FromFfi for crate::content::ContentId {
        type FfiType = u64;
        fn from_ffi(ffi: Self::FfiType) -> Self {
            FfiObject::from_packed(ffi).deserialize()
        }
    }
}