Skip to main content

lotus_shared/
content.rs

1//! Content-Identifikatoren, die zwischen Scripts und Engine geteilt werden.
2//!
3//! Content identifiers shared between scripts and the engine.
4
5use serde::{Deserialize, Serialize};
6
7/// Eindeutiger Identifikator für ein Content-Element.
8///
9/// A unique identifier for a content item.
10#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, Default)]
11pub struct ContentId {
12    /// User-ID des Content-Elements.
13    ///
14    /// The user ID of the content item.
15    pub user_id: i32,
16    /// Sub-ID des Content-Elements.
17    ///
18    /// The sub ID of the content item.
19    pub sub_id: i32,
20}
21
22impl Eq for ContentId {}
23
24impl std::hash::Hash for ContentId {
25    #[inline(always)]
26    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
27        self.user_id.hash(state);
28        self.sub_id.hash(state);
29    }
30}
31
32#[cfg(feature = "ffi")]
33mod ffi {
34    use lotus_script_sys::{FfiObject, FromFfi};
35
36    impl FromFfi for crate::content::ContentId {
37        type FfiType = u64;
38        fn from_ffi(ffi: Self::FfiType) -> Self {
39            FfiObject::from_packed(ffi).deserialize()
40        }
41    }
42}