ras_filesystem/domain/
repository.rs1use std::path::PathBuf;
2
3use async_trait::async_trait;
4use ras_errors::AppError;
5use serde::{Deserialize, Serialize};
6use thiserror::Error;
7
8use crate::domain::file::{FileExtension, FileSystemFile};
9
10#[derive(Debug, Error)]
11pub enum FileSystemError {
12 #[error("invalid filename: {0}")]
13 InvalidFilename(String),
14 #[error("io: {0}")]
15 Io(String),
16}
17
18impl From<FileSystemError> for AppError {
19 fn from(e: FileSystemError) -> Self {
20 Self::ValidationError(e.to_string())
21 }
22}
23
24#[derive(Debug, Clone, Default, Serialize, Deserialize)]
25pub struct FileSystemState {
26 pub root: PathBuf,
27 pub files: Vec<FileSummary>,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct FileSummary {
32 pub name: String,
33 pub extension: FileExtension,
34 pub size_bytes: u64,
35}
36
37#[async_trait]
38pub trait FileSystemPort: Send + Sync + 'static {
39 async fn read(&self, name: &str) -> Result<FileSystemFile, AppError>;
40 async fn write(&self, file: FileSystemFile) -> Result<(), AppError>;
41 async fn append(&self, name: &str, content: &str) -> Result<(), AppError>;
42 async fn list(&self) -> Result<Vec<FileSummary>, AppError>;
43 async fn snapshot(&self) -> Result<FileSystemState, AppError>;
44}