[][src]Struct qstorage::QStorage

pub struct QStorage {
    pub path_name: String,
    pub chunk_size: u64,
    pub block_size: u64,
    pub engine: Engine,
    pub path: &'static str,
    pub db_path: &'static str,
    pub drop_path: &'static str,
}

Object storage instance.

  • path_name Storage root directory.
  • chunk_size Slice file size.
  • block_size Block size.
  • context Options file descriptor.
  • db_context Indexs file descriptor.
  • drop_context Drop indexs file descriptor.

Fields

path_name: Stringchunk_size: u64block_size: u64engine: Enginepath: &'static strdb_path: &'static strdrop_path: &'static str

Methods

impl QStorage[src]

pub fn new(
    dirname: String,
    chunk_size: u64,
    block_size: u64
) -> Result<Self, Error>
[src]

Create an object storage instance.

Initialize an instance with the given configuration.

example

let dirname = String::from("./storage");
QStorage::new(dirname, 10737418240, 1048576)?;

pub fn ready(&mut self) -> Result<&mut Self, Error>[src]

Initialization instance.

Preparation before work.

example

let dirname = String::from("./storage");
QStorage::new(dirname, 10737418240, 1048576)?.ready()?;

pub fn closed(&mut self) -> Result<(), Error>[src]

Turn off the storage system.

Used for shutdown processing.

  • This is a required operation. You must do the final cleanup before each shutdown, save the state, you can also call this function each time you need to save the state.
  • This operation will write the memory data to the file system.
  • For example, listen to the exit event of the process, and then call this function.

example

let dirname = String::from("./storage");
QStorage::new(dirname, 10737418240, 1048576)?.ready()?.closed()?;

pub fn insert(&mut self, key: String, value: Vec<u8>) -> Result<(), Error>[src]

Write data to file storage.

Write key pair data to the file system.

example

let dirname = String::from("./storage");
let mut qstorage = QStorage::new(dirname, 10737418240, 1048576)?.ready()?;
qstorage.insert(String::from("hello"), "word".as_bytes().to_vec())?;

pub fn get(&mut self, key: String) -> Result<Option<Vec<u8>>, Error>[src]

Retrieve data.

Get data based on the specified key.

example

let dirname = String::from("./storage");
let mut qstorage = QStorage::new(dirname, 10737418240, 1048576)?.ready()?;
qstorage.insert(String::from("hello"), "word".as_bytes().to_vec())?;
qstorage.get(String::from("hello"))?;

pub fn remove(&mut self, key: String) -> bool[src]

Delete data.

Remove data based on the specified key.

example

let dirname = String::from("./storage");
let mut qstorage = QStorage::new(dirname, 10737418240, 1048576)?.ready()?;
qstorage.insert(String::from("hello"), "word".as_bytes().to_vec())?;
qstorage.remove(String::from("hello"))?;

Auto Trait Implementations

impl Send for QStorage

impl Sync for QStorage

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]