sz_rust_sdk/types.rs
1//! Common types and type aliases for the Senzing SDK
2
3/// Entity ID type
4pub type EntityId = i64;
5
6/// Configuration ID type
7pub type ConfigId = i64;
8
9/// Feature ID type
10pub type FeatureId = i64;
11
12/// Export handle type
13pub type ExportHandle = i64;
14
15/// Data source code type
16pub type DataSourceCode = String;
17
18/// Record ID type
19pub type RecordId = String;
20
21/// JSON string type for Senzing data exchange
22pub type JsonString = String;
23
24/// Reference to an entity - either by direct ID or by record key.
25///
26/// This enum allows functions to accept either an entity ID or a record
27/// identifier (data source + record ID) to refer to an entity.
28///
29/// # Examples
30///
31/// ```no_run
32/// use sz_rust_sdk::prelude::*;
33///
34/// // Reference by entity ID (automatic conversion)
35/// let entity_id: EntityId = 1001;
36/// let ref1: EntityRef = entity_id.into();
37///
38/// // Reference by record key
39/// let ref2 = EntityRef::Record {
40/// data_source: "CUSTOMERS",
41/// record_id: "CUST001",
42/// };
43/// ```
44#[derive(Debug, Clone, PartialEq, Eq)]
45pub enum EntityRef<'a> {
46 /// Entity identified by its entity ID
47 Id(EntityId),
48 /// Entity identified by a record's data source and record ID
49 Record {
50 /// The data source code (e.g., "CUSTOMERS")
51 data_source: &'a str,
52 /// The record ID within the data source
53 record_id: &'a str,
54 },
55}
56
57impl From<EntityId> for EntityRef<'_> {
58 fn from(id: EntityId) -> Self {
59 EntityRef::Id(id)
60 }
61}
62
63impl<'a> EntityRef<'a> {
64 /// Create an EntityRef from a record key
65 pub fn from_record(data_source: &'a str, record_id: &'a str) -> Self {
66 EntityRef::Record {
67 data_source,
68 record_id,
69 }
70 }
71}