qubit_fs/directory/
create_directory_outcome.rs1#[derive(Clone, Copy, Debug, Eq, PartialEq)]
22pub struct CreateDirectoryOutcome {
23 already_existed: bool,
25 created_ancestors: Option<u64>,
27}
28
29impl CreateDirectoryOutcome {
30 #[inline]
33 #[must_use]
34 pub const fn new(already_existed: bool) -> Self {
35 Self {
36 already_existed,
37 created_ancestors: None,
38 }
39 }
40
41 #[inline]
43 #[must_use]
44 pub const fn already_existed(self) -> bool {
45 self.already_existed
46 }
47
48 #[inline]
50 #[must_use]
51 pub const fn with_created_ancestors(mut self, count: u64) -> Self {
52 self.created_ancestors = Some(count);
53 self
54 }
55
56 #[inline]
58 #[must_use]
59 pub const fn created_ancestors(self) -> Option<u64> {
60 self.created_ancestors
61 }
62}
63
64#[cfg(test)]
65mod tests {
66 use std::hint::black_box;
67
68 use super::CreateDirectoryOutcome;
69
70 #[test]
71 fn outcome_accessors_are_executed_at_runtime() {
72 let constructor: fn(bool) -> CreateDirectoryOutcome = black_box(CreateDirectoryOutcome::new);
73 let with_ancestors: fn(CreateDirectoryOutcome, u64) -> CreateDirectoryOutcome =
74 black_box(CreateDirectoryOutcome::with_created_ancestors);
75 let already_existed: fn(CreateDirectoryOutcome) -> bool = black_box(CreateDirectoryOutcome::already_existed);
76 let created_ancestors: fn(CreateDirectoryOutcome) -> Option<u64> =
77 black_box(CreateDirectoryOutcome::created_ancestors);
78
79 let outcome = with_ancestors(constructor(true), 2);
80 assert!(already_existed(outcome));
81 assert_eq!(Some(2), created_ancestors(outcome));
82 }
83}