pub fn open_or_create(file_path: &str, mut cfg: Cfg) -> Result<Self, LoadFileError> {
        create_dirs_to_path_if_not_exist(file_path)?;

        let mut file = OpenOptions::new().read(true).write(true).append(true).create(true).open(file_path)?;
        file.lock_exclusive()?;

        // load current map from history file
        let map = match &mut cfg.format {
            Format::Text(_, after_read_callback) => {
                let mut callback = None;
                std::mem::swap(after_read_callback, &mut callback);
                map_from_text_file::<Map, Key, Value, _, _>(&mut file, &mut cfg.integrity, callback)?
            },
            Format::Bin(_,  after_read_callback) => {
                let mut callback = None;
                std::mem::swap(after_read_callback, &mut callback);
                map_from_bin_file::<Map, Key, Value, _, _>(&mut file, &mut cfg.integrity, callback)?
            },
        };

        Ok(MapWithFile {
            map,
            file_worker: FileWorker::new(file, cfg.write_error_callback.take()),
            indexes: Vec::new(),
            cfg,
        })
    }
/// Constructs file based map.
/// Open/create file and loads the entire history of
/// changes from file restoring the last state of the map.
/// If file is exist then load map from file. If file not is not exist then create new file.
Constructs file based map.
Open/create file and loads the entire history of
changes from file restoring the last state of the map.
If file is exist then load map from file. If file not is not exist then create new file.
Constructs file based map . Open / create file and loads the entire history of changes from file restoring the last state of the map . If file is exist then load map from file . If file not is not exist then create new file .
pub fn open_or_create(file_path: &str, mut cfg: Cfg) -> Result<Self, LoadFileError> {
        create_dirs_to_path_if_not_exist(file_path)?;
        let mut file = OpenOptions::new().read(true).write(true).append(true).create(true).open(file_path)?;
        file.lock_exclusive()?;
        // load current map from history file
        let map = match &mut cfg.format {
            Format::Text(_, after_read_callback) => {
                let mut callback = None;
                std::mem::swap(after_read_callback, &mut callback);
                map_from_text_file::<Map, Key, Value, _, _>(&mut file, &mut cfg.integrity, callback)?
            },
            Format::Bin(_,  after_read_callback) => {
                let mut callback = None;
                std::mem::swap(after_read_callback, &mut callback);
                map_from_bin_file::<Map, Key, Value, _, _>(&mut file, &mut cfg.integrity, callback)?
            },
        };
        Ok(MapWithFile {
            map,
            file_worker: FileWorker::new(file, cfg.write_error_callback.take()),
            indexes: Vec::new(),
            cfg,
        })
    }
pub fn open_or_create ( file_path : & str , mut cfg : Cfg ) -> Result < Self , LoadFileError > { create_dirs_to_path_if_not_exist ( file_path ) ? ; let mut file = OpenOptions :: new ( ) . read ( true ) . write ( true ) . append ( true ) . create ( true ) . open ( file_path ) ? ; file . lock_exclusive ( ) ? ; // load current map from history file let map = match & mut cfg . format { Format :: Text ( _ , after_read_callback ) => { let mut callback = None ; std :: mem :: swap ( after_read_callback , & mut callback ) ; map_from_text_file :: < Map , Key , Value , _ , _ > ( & mut file , & mut cfg . integrity , callback ) ? } , Format :: Bin ( _ , after_read_callback ) => { let mut callback = None ; std :: mem :: swap ( after_read_callback , & mut callback ) ; map_from_bin_file :: < Map , Key , Value , _ , _ > ( & mut file , & mut cfg . integrity , callback ) ? } , } ; Ok ( MapWithFile { map , file_worker : FileWorker :: new ( file , cfg . write_error_callback . take ( ) ) , indexes : Vec :: new ( ) , cfg , } ) }
Constructs file based map.
Constructs file based map .
file_path
&str
cfg
Cfg
file_path
&str
cfg
Cfg