molframe_core/execution/
storage.rs1use std::path::{Path, PathBuf};
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub struct ScratchPolicy {
8 max_bytes: usize,
9}
10
11impl ScratchPolicy {
12 #[must_use]
14 pub const fn new(max_bytes: usize) -> Self {
15 Self { max_bytes }
16 }
17
18 #[must_use]
20 pub const fn max_bytes(self) -> usize {
21 self.max_bytes
22 }
23}
24
25impl Default for ScratchPolicy {
26 fn default() -> Self {
27 Self::new(8_000_000)
28 }
29}
30
31#[derive(Clone, Debug, Default, PartialEq, Eq)]
33pub enum TempStoragePolicy {
34 #[default]
36 Disabled,
37 Directory {
39 root: PathBuf,
41 max_bytes: u64,
43 },
44}
45
46impl TempStoragePolicy {
47 #[must_use]
49 pub fn directory(root: impl Into<PathBuf>, max_bytes: u64) -> Self {
50 Self::Directory {
51 root: root.into(),
52 max_bytes,
53 }
54 }
55
56 #[must_use]
58 pub fn root(&self) -> Option<&Path> {
59 match self {
60 Self::Disabled => None,
61 Self::Directory { root, .. } => Some(root),
62 }
63 }
64
65 #[must_use]
67 pub const fn max_bytes(&self) -> u64 {
68 match self {
69 Self::Disabled => 0,
70 Self::Directory { max_bytes, .. } => *max_bytes,
71 }
72 }
73}
74
75#[cfg(test)]
76#[path = "storage_tests.rs"]
77mod tests;