commit d8bd378799edd344daf832809aecc310af2f9580
parent f6258f829c64d6f9ec1a34a595c88b4ae078312b
Author: triesap <triesap@radroots.dev>
Date: Mon, 19 Jan 2026 00:50:43 +0000
app-core: add filesystem types and trait
- define filesystem result aliases and file metadata types
- add async filesystem trait for open/info/read operations
- model filesystem open result with explicit path field
- add unit tests for file info flags and open result
Diffstat:
2 files changed, 68 insertions(+), 0 deletions(-)
diff --git a/crates/core/src/fs/mod.rs b/crates/core/src/fs/mod.rs
@@ -1,3 +1,11 @@
pub mod error;
+pub mod types;
pub use error::{RadrootsClientFsError, RadrootsClientFsErrorMessage};
+pub use types::{
+ RadrootsClientFs,
+ RadrootsClientFsFileInfo,
+ RadrootsClientFsOpenResult,
+ RadrootsClientFsReadBinResult,
+ RadrootsClientFsResult,
+};
diff --git a/crates/core/src/fs/types.rs b/crates/core/src/fs/types.rs
@@ -0,0 +1,60 @@
+use async_trait::async_trait;
+
+use super::RadrootsClientFsError;
+
+pub type RadrootsClientFsResult<T> = Result<T, RadrootsClientFsError>;
+pub type RadrootsClientFsReadBinResult = RadrootsClientFsResult<Vec<u8>>;
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct RadrootsClientFsOpenResult {
+ pub path: String,
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct RadrootsClientFsFileInfo {
+ pub size: u64,
+ pub is_file: bool,
+ pub is_directory: bool,
+ pub accessed_at: Option<u64>,
+ pub modified_at: Option<u64>,
+ pub created_at: Option<u64>,
+}
+
+#[async_trait(?Send)]
+pub trait RadrootsClientFs {
+ async fn exists(&self, path: &str) -> RadrootsClientFsResult<bool>;
+ async fn open(&self, path: &str) -> RadrootsClientFsResult<RadrootsClientFsOpenResult>;
+ async fn info(&self, path: &str) -> RadrootsClientFsResult<RadrootsClientFsFileInfo>;
+ async fn read_bin(&self, path: &str) -> RadrootsClientFsReadBinResult;
+}
+
+#[cfg(test)]
+mod tests {
+ use super::{RadrootsClientFsFileInfo, RadrootsClientFsOpenResult};
+
+ #[test]
+ fn file_info_tracks_flags() {
+ let info = RadrootsClientFsFileInfo {
+ size: 42,
+ is_file: true,
+ is_directory: false,
+ accessed_at: Some(1),
+ modified_at: Some(2),
+ created_at: None,
+ };
+ assert!(info.is_file);
+ assert!(!info.is_directory);
+ assert_eq!(info.size, 42);
+ assert_eq!(info.accessed_at, Some(1));
+ assert_eq!(info.modified_at, Some(2));
+ assert_eq!(info.created_at, None);
+ }
+
+ #[test]
+ fn open_result_preserves_path() {
+ let open = RadrootsClientFsOpenResult {
+ path: String::from("path"),
+ };
+ assert_eq!(open.path, "path");
+ }
+}