frclib_datalog/
lib.rs

1//! # frclib-datalog
2#![cfg_attr(test, feature(test))]
3#![deny(clippy::all, clippy::pedantic, clippy::nursery)]
4#![deny(
5    warnings,
6    missing_copy_implementations,
7    single_use_lifetimes,
8    variant_size_differences,
9    arithmetic_overflow,
10    missing_debug_implementations,
11    trivial_casts,
12    trivial_numeric_casts,
13    unused_import_braces,
14    unused_results,
15    unused_lifetimes,
16    unused_unsafe,
17    useless_ptr_null_checks,
18    cenum_impl_drop_cast,
19    while_true,
20    unused_features,
21    absolute_paths_not_starting_with_crate,
22    unused_allocation,
23    unreachable_code,
24    unused_comparisons,
25    unused_parens,
26    asm_sub_register,
27    break_with_label_and_loop,
28    bindings_with_variant_name,
29    anonymous_parameters,
30    clippy::unwrap_used,
31    clippy::panicking_unwrap,
32    missing_abi,
33    missing_fragment_specifier,
34    clippy::missing_safety_doc,
35    clippy::missing_asserts_for_indexing,
36    clippy::missing_assert_message,
37    clippy::possible_missing_comma,
38    deprecated
39)]
40#![allow(clippy::module_name_repetitions, clippy::option_if_let_else)]
41#![cfg_attr(
42    not(test),
43    forbid(
44        clippy::panic,
45        clippy::todo,
46        clippy::unimplemented,
47        clippy::expect_used
48    )
49)]
50#![cfg_attr(not(test), warn(missing_docs))]
51
52#[macro_use]
53extern crate bitflags;
54
55pub(crate) mod proto;
56
57/// # Errors
58/// 
59/// TODO
60pub mod error;
61
62/// # Reading
63/// 
64/// TODO
65pub mod reader;
66
67/// # Writing
68/// 
69/// TODO
70pub mod writer;
71
72#[cfg(test)]
73mod test;
74
75pub use error::DataLogError;
76pub use reader::DataLogReader;
77pub use writer::DataLogWriter;
78
79use frclib_core::value::FrcTimestamp;
80
81///A unique identifier for a data entry
82type EntryId = u32;
83///A string representing a data entry name
84type EntryName = String;
85///A string representing a data entry type
86type EntryType = String;
87///A string in json format representing data entry metadata
88type EntryMetadata = String;
89
90
91/// Gets the uptime in microseconds
92pub(crate) fn now() -> FrcTimestamp {
93    frclib_core::time::uptime().as_micros()
94        .try_into()
95        .unwrap_or(FrcTimestamp::MAX)
96}
97
98/// A timestamped value
99#[derive(Debug, Clone)]
100pub struct TimestampedValue<T> {
101    /// The timestamp of the value
102    pub timestamp: FrcTimestamp,
103    /// The value
104    pub value: T,
105}
106
107impl <T> TimestampedValue<T> {
108    /// Creates a new timestamped value
109    pub const fn new(timestamp: FrcTimestamp, value: T) -> Self {
110        Self {
111            timestamp,
112            value
113        }
114    }
115
116    /// Creates a new timestamped value with the current time
117    pub fn new_now(value: T) -> Self {
118        Self {
119            timestamp: now(),
120            value
121        }
122    }
123}