pub struct Storage {
pub entries: HashMap<String, Entry>,
}
Fields§
§entries: HashMap<String, Entry>
Implementations§
Source§impl Storage
impl Storage
Sourcepub fn add<K: ToString, T: Into<Entry>>(
&mut self,
key: K,
entry: T,
) -> Option<Entry>
pub fn add<K: ToString, T: Into<Entry>>( &mut self, key: K, entry: T, ) -> Option<Entry>
Add new entry to storage
Works as HashMap::insert
method, so will return Some(Entry)
if it replaced older value
use kinda_virtual_fs::*;
let mut storage = Storage::default();
storage.add("example 1", "Hello, World!");
storage.add("example 2", Entry::new("Also accepts Entry struct"));
Sourcepub fn map<T: ToString>(&self, key: T) -> Result<String>
pub fn map<T: ToString>(&self, key: T) -> Result<String>
Try to map entry with specific key
use kinda_virtual_fs::*;
let mut storage = Storage::default();
storage.add("example", "Hello, World!");
let file_path = storage.map("example").expect("Failed to map entry");
let file_content = std::fs::read_to_string(file_path).expect("Failed to read mapped entry");
assert_eq!(&file_content, "Hello, World!");
Sourcepub fn unmap<T: ToString>(&self, key: T) -> Result<()>
pub fn unmap<T: ToString>(&self, key: T) -> Result<()>
Unmap entry with specific key
Will return Ok(())
if there’s no entry with specified key
Entry will be automatically unmapped when its value is no more needed
§Manual unmapping
use kinda_virtual_fs::*;
let mut storage = Storage::default();
storage.add("example", "Hello, World!");
let path = storage.map("example").unwrap();
assert_eq!(std::path::Path::new(&path).exists(), true);
storage.unmap("example");
assert_eq!(std::path::Path::new(&path).exists(), false);
§Automatic unmapping
use kinda_virtual_fs::*;
let mut storage = Storage::default();
storage.add("example", "Hello, World!");
let path = storage.map("example").unwrap();
assert_eq!(std::path::Path::new(&path).exists(), true);
storage.remove("example");
assert_eq!(std::path::Path::new(&path).exists(), false);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Storage
impl RefUnwindSafe for Storage
impl Send for Storage
impl Sync for Storage
impl Unpin for Storage
impl UnwindSafe for Storage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more