-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobject.rs
More file actions
53 lines (46 loc) · 1.24 KB
/
Copy pathobject.rs
File metadata and controls
53 lines (46 loc) · 1.24 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::value::RuntimeValue;
use indexmap::IndexMap;
use std::sync::atomic::{AtomicU64, Ordering};
static NEXT_OBJECT_ID: AtomicU64 = AtomicU64::new(1);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ObjectId(pub u64);
impl ObjectId {
/// Generates a globally unique incrementing object identifier.
pub fn next() -> Self {
Self(NEXT_OBJECT_ID.fetch_add(1, Ordering::SeqCst))
}
}
/// Runtime struct instance.
#[derive(Debug, Clone)]
pub struct StructInstance {
pub id: ObjectId,
pub name: String,
pub fields: IndexMap<String, RuntimeValue>,
pub is_const: bool,
}
impl StructInstance {
pub fn new(name: String, fields: IndexMap<String, RuntimeValue>, is_const: bool) -> Self {
Self {
id: ObjectId::next(),
name,
fields,
is_const,
}
}
}
/// Runtime class/model instance.
#[derive(Debug, Clone)]
pub struct ModelInstance {
pub id: ObjectId,
pub name: String,
pub fields: IndexMap<String, RuntimeValue>,
}
impl ModelInstance {
pub fn new(name: String, fields: IndexMap<String, RuntimeValue>) -> Self {
Self {
id: ObjectId::next(),
name,
fields,
}
}
}