ableos/ableos/src/proto_filetable/mod.rs

57 lines
1.4 KiB
Rust

//! A file table module for AbleOS
//!
//! This module provides a file table interface for AbleOS.
//!
//! # Examples
//! ```
//! use relib::filesystem::ProtoFileTable;
//! let mut file_table = ProtoFileTable::new();
//! file_table.add_file("test.txt", "Hello, world!".as_bytes());
//! let file = file_table.get_file("test.txt");
//! assert_eq!(file.unwrap().as_slice(), "Hello, world!".as_bytes());
//! ```
//! # Notes
//! The file table is a simple in-memory hashmap.
//! The file table is not thread safe.
//! The file table is not persistent.
use hashbrown::HashMap;
pub mod contain;
pub mod file;
use file::File;
/// A prototype file table for AbleOS
///
/// This module provides a file table interface for AbleOS.
///
/// # Examples
/// ```
/// use crate::filesystem::ProtoFileTable;
/// let mut file_table = ProtoFileTable::new();
/// file_table.add_file("test.txt", "Hello, world!".as_bytes());
/// let file = file_table.get_file("test.txt");
/// assert_eq!(file.unwrap().as_slice(), "Hello, world!".as_bytes());
/// ```
pub struct ProtoFileTable {
files: HashMap<String, File>,
}
impl ProtoFileTable {
pub fn new() -> ProtoFileTable {
ProtoFileTable {
files: HashMap::new(),
}
}
pub fn add_file(&mut self, path: &str, contents: File) {
self.files.insert(path.to_string(), contents);
}
pub fn get_file(&self, path: &str) -> Option<&File> {
self.files.get(path)
}
}
#[cfg(test)]
mod tests;