#![warn(
missing_docs,
elided_lifetimes_in_paths,
explicit_outlives_requirements,
missing_abi,
noop_method_call,
pointer_structural_match,
semicolon_in_expressions_from_macros,
unused_import_braces,
unused_lifetimes,
clippy::cargo,
clippy::missing_panics_doc,
clippy::doc_markdown,
clippy::ptr_as_ptr,
clippy::cloned_instead_of_copied,
clippy::unreadable_literal
)]
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
#[cfg(feature = "dfs")]
mod dfs;
#[cfg(feature = "imfs")]
mod imfs;
mod pattern;
mod file;
pub mod error;
#[cfg(feature = "dfs")]
pub use dfs::{DirectoryBackedFs, Error as DfsError};
#[cfg(feature = "imfs")]
pub use imfs::{Error as ImfsError, InMemoryFs};
pub use pattern::{TagPattern, TagPredicate};
pub use file::{FileId, Tag, Group};
pub use error::{Error, ErrorKind};
use alloc::boxed::Box;
use alloc::collections::BTreeSet;
use alloc::vec::Vec;
pub trait FileSystem {
type Error: Error;
fn add_file<I>(&self, data: &[u8], tags: I) -> Result<FileId, Self::Error>
where
I: IntoIterator<Item = Tag>;
fn edit_file<I>(
&self,
id: FileId,
data: Option<&[u8]>,
tags: Option<I>,
) -> Result<(), Self::Error>
where
I: IntoIterator<Item = Tag>;
fn remove_file(&self, id: FileId) -> Result<(), Self::Error>;
fn search_tags<P>(&self, tags: P) -> Result<Vec<FileId>, Self::Error>
where
P: TagPattern;
fn get_info(&self, id: FileId) -> Result<FileInfo, Self::Error>;
}
#[derive(Debug)]
pub struct FileInfo {
id: FileId,
tags: BTreeSet<Tag>,
data: Box<[u8]>,
}
impl FileInfo {
pub fn id(&self) -> FileId {
self.id
}
pub fn tags(&self) -> &BTreeSet<Tag> {
&self.tags
}
pub fn data(&self) -> &[u8] {
&*self.data
}
}