#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CreateDirectoryOutcome {
already_existed: bool,
created_ancestors: Option<u64>,
}
impl CreateDirectoryOutcome {
#[inline]
#[must_use]
pub const fn new(already_existed: bool) -> Self {
Self {
already_existed,
created_ancestors: None,
}
}
#[inline]
#[must_use]
pub const fn already_existed(self) -> bool {
self.already_existed
}
#[inline]
#[must_use]
pub const fn with_created_ancestors(mut self, count: u64) -> Self {
self.created_ancestors = Some(count);
self
}
#[inline]
#[must_use]
pub const fn created_ancestors(self) -> Option<u64> {
self.created_ancestors
}
}
#[cfg(test)]
mod tests {
use std::hint::black_box;
use super::CreateDirectoryOutcome;
#[test]
fn outcome_accessors_are_executed_at_runtime() {
let constructor: fn(bool) -> CreateDirectoryOutcome = black_box(CreateDirectoryOutcome::new);
let with_ancestors: fn(CreateDirectoryOutcome, u64) -> CreateDirectoryOutcome =
black_box(CreateDirectoryOutcome::with_created_ancestors);
let already_existed: fn(CreateDirectoryOutcome) -> bool = black_box(CreateDirectoryOutcome::already_existed);
let created_ancestors: fn(CreateDirectoryOutcome) -> Option<u64> =
black_box(CreateDirectoryOutcome::created_ancestors);
let outcome = with_ancestors(constructor(true), 2);
assert!(already_existed(outcome));
assert_eq!(Some(2), created_ancestors(outcome));
}
}