tugraph/raw/
types.rs

1// Copyright 2023 antkiller
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::ffi;
16
17raw_pod_rustlize!(
18    RawEdgeUid,
19    lgraph_api_edge_uid_t,
20    lgraph_api_edge_euid_destroy,
21);
22
23impl RawEdgeUid {
24    pub(crate) fn src(&self) -> i64 {
25        unsafe { ffi::lgraph_api_edge_euid_get_src(self.inner) }
26    }
27
28    pub(crate) fn lid(&self) -> u16 {
29        unsafe { ffi::lgraph_api_edge_euid_get_lid(self.inner) }
30    }
31
32    pub(crate) fn tid(&self) -> i64 {
33        unsafe { ffi::lgraph_api_edge_euid_get_tid(self.inner) }
34    }
35
36    pub(crate) fn eid(&self) -> i64 {
37        unsafe { ffi::lgraph_api_edge_euid_get_eid(self.inner) }
38    }
39
40    pub(crate) fn dst(&self) -> i64 {
41        unsafe { ffi::lgraph_api_edge_euid_get_dst(self.inner) }
42    }
43}
44
45raw_pod_rustlize!(RawDate, lgraph_api_date_t, lgraph_api_date_destroy);
46impl RawDate {
47    pub(crate) fn new() -> Self {
48        unsafe {
49            RawDate {
50                inner: ffi::lgraph_api_create_date(),
51            }
52        }
53    }
54
55    pub(crate) fn from_days(days: i32) -> Self {
56        unsafe {
57            RawDate {
58                inner: ffi::lgraph_api_create_date_days(days),
59            }
60        }
61    }
62
63    pub(crate) fn from_ymd(year: i32, month: u32, day: u32) -> Self {
64        unsafe {
65            RawDate {
66                inner: ffi::lgraph_api_create_date_ymd(year, month, day),
67            }
68        }
69    }
70
71    pub(crate) fn days_since_epoch(&self) -> i32 {
72        unsafe { ffi::lgraph_api_date_days_since_epoch(self.inner) }
73    }
74}
75
76impl Default for RawDate {
77    fn default() -> Self {
78        Self::new()
79    }
80}
81
82raw_pod_rustlize!(
83    RawDateTime,
84    lgraph_api_date_time_t,
85    lgraph_api_date_time_destroy,
86);
87
88impl RawDateTime {
89    pub(crate) fn new() -> Self {
90        unsafe {
91            RawDateTime {
92                inner: ffi::lgraph_api_create_date_time(),
93            }
94        }
95    }
96
97    pub(crate) fn from_ymdhms(
98        year: i32,
99        month: u32,
100        day: u32,
101        hour: u32,
102        minute: u32,
103        second: u32,
104    ) -> Self {
105        unsafe {
106            RawDateTime {
107                inner: ffi::lgraph_api_create_date_time_ymdhms(
108                    year, month, day, hour, minute, second,
109                ),
110            }
111        }
112    }
113
114    pub(crate) fn from_seconds_since_epoch(seconds: i64) -> Self {
115        unsafe {
116            RawDateTime {
117                inner: ffi::lgraph_api_create_date_time_seconds(seconds),
118            }
119        }
120    }
121
122    pub(crate) fn seconds_since_epoch(&self) -> i64 {
123        unsafe { ffi::lgraph_api_date_time_seconds_since_epoch(self.inner) }
124    }
125}
126
127impl Default for RawDateTime {
128    fn default() -> Self {
129        Self::new()
130    }
131}