pub struct RecordAdd {
pub record_id: ValidName,
pub meta: Option<ValidMeta>,
pub components: Vec<Component>,
pub start_time: DateTime<Utc>,
pub stop_time: Option<DateTime<Utc>>,
}
Expand description
RecordAdd
represents a single accountable unit that is added to Auditor.
Use the constructor to build a new record. A stop time can be added with the with_stop_time()
method.
§Note
All strings must not include the characters /()"<>\{}
.
When created using the constructor, the record is already valid in terms of all checks that Auditor performs when receiving it.
§Examples
Create a record with a valid ID:
use chrono::{DateTime, TimeZone, Utc};
let start_time: DateTime<Utc> = Utc.with_ymd_and_hms(2023, 1, 1, 0, 0, 0).unwrap();
let component_cpu = Component::new("CPU", 10)?
.with_score(Score::new("HEPSPEC06", 9.2)?);
let component_mem = Component::new("MEM", 32)?;
let components = vec![component_cpu, component_mem];
let mut meta = HashMap::new();
meta.insert("site_id", vec!["site1"]);
meta.insert("features", vec!["ssd", "gpu"]);
let record = RecordAdd::new("123456", meta, components, start_time)?;
Create a record with a valid ID and a stop time:
let start_time: DateTime<Utc> = Utc.with_ymd_and_hms(2023, 1, 1, 0, 0, 0).unwrap();
let stop_time: DateTime<Utc> = Utc.with_ymd_and_hms(2023, 1, 1, 12, 0, 0).unwrap();
let record = RecordAdd::new("123456", meta, components, start_time)?
.with_stop_time(stop_time);
Create a record with an invalid ID:
let record = RecordAdd::new("123/456", meta, components, start_time);
assert!(record.is_err());
Ok(())
Fields§
§record_id: ValidName
Unique identifier of the record.
meta: Option<ValidMeta>
Meta information, a collection of key value pairs in the form of String
-> Vec<String>
.
components: Vec<Component>
List of components that are accounted for.
start_time: DateTime<Utc>
Start time of the record.
stop_time: Option<DateTime<Utc>>
Stop time of the record.
Implementations§
source§impl RecordAdd
impl RecordAdd
sourcepub fn new<T: AsRef<str>>(
record_id: T,
meta: HashMap<T, Vec<T>>,
components: Vec<Component>,
start_time: DateTime<Utc>
) -> Result<Self, Error>
pub fn new<T: AsRef<str>>( record_id: T, meta: HashMap<T, Vec<T>>, components: Vec<Component>, start_time: DateTime<Utc> ) -> Result<Self, Error>
Constructor.
§Errors
anyhow::Error
- If there was an invalid character (/()"<>\{}
) in therecord_id
or themeta
information.
sourcepub fn with_stop_time(self, stop_time: DateTime<Utc>) -> Self
pub fn with_stop_time(self, stop_time: DateTime<Utc>) -> Self
Set the stop time to the record.
Trait Implementations§
source§impl<'de> Deserialize<'de> for RecordAdd
impl<'de> Deserialize<'de> for RecordAdd
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for RecordAdd
impl RefUnwindSafe for RecordAdd
impl Send for RecordAdd
impl Sync for RecordAdd
impl Unpin for RecordAdd
impl UnwindSafe for RecordAdd
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more