pub fn insert(&mut self, key: Key, value: Value) -> Result<Option<Value>, SerializedError> {
        match & mut self.cfg.format {
            Format::Text(before_write_callback, _) => {
                let mut line = text_file_line_of_insert(&key, &value, &mut self.cfg.integrity)?;
                let old_value = self.map.insert(key.clone(), value.clone());
                if let Some(f) = before_write_callback {
                    f(&mut line);
                }
                self.file_worker.write_string(line);
                self.update_index_when_insert(&key, &value, &old_value);
                Ok(old_value)
            },
            Format::Bin(before_write_callback, _) => {
                let mut block = bin_file_block_of_insert(&key, &value, &mut self.cfg.integrity)?;
                let old_value = self.map.insert(key.clone(), value.clone());
                if let Some(f) = before_write_callback {
                    f(&mut block);
                }
                if let Some(f) = before_write_callback {
                    f(&mut block);
                }
                self.file_worker.write_bytes(block);
                self.update_index_when_insert(&key, &value, &old_value);
                Ok(old_value)
            },
        }
    }
/// Inserts a key-value pair into the map.
/// Insert into the map will immediately, and to disk later in a background thread.
///
/// # Errors
///
/// Error can by returned only if serde_json::to_string() return error:
/// Serialization can fail if 'Key' or 'Value' s implementation of `Serialize` decides to
/// fail, or if 'Key' or 'Value' contains a map with non-string keys.
///
Inserts a key-value pair into the map.
Insert into the map will immediately, and to disk later in a background thread.
Inserts a key - value pair into the map . Insert into the map will immediately and to disk later in a background thread .
pub fn insert(&mut self, key: Key, value: Value) -> Result<Option<Value>, SerializedError> {
        match & mut self.cfg.format {
            Format::Text(before_write_callback, _) => {
                let mut line = text_file_line_of_insert(&key, &value, &mut self.cfg.integrity)?;
                let old_value = self.map.insert(key.clone(), value.clone());
                if let Some(f) = before_write_callback {
                    f(&mut line);
                }
                self.file_worker.write_string(line);
                self.update_index_when_insert(&key, &value, &old_value);
                Ok(old_value)
            },
            Format::Bin(before_write_callback, _) => {
                let mut block = bin_file_block_of_insert(&key, &value, &mut self.cfg.integrity)?;
                let old_value = self.map.insert(key.clone(), value.clone());
                if let Some(f) = before_write_callback {
                    f(&mut block);
                }
                if let Some(f) = before_write_callback {
                    f(&mut block);
                }
                self.file_worker.write_bytes(block);
                self.update_index_when_insert(&key, &value, &old_value);
                Ok(old_value)
            },
        }
    }
pub fn insert ( & mut self , key : Key , value : Value ) -> Result < Option < Value > , SerializedError > { match & mut self . cfg . format { Format :: Text ( before_write_callback , _ ) => { let mut line = text_file_line_of_insert ( & key , & value , & mut self . cfg . integrity ) ? ; let old_value = self . map . insert ( key . clone ( ) , value . clone ( ) ) ; if let Some ( f ) = before_write_callback { f ( & mut line ) ; } self . file_worker . write_string ( line ) ; self . update_index_when_insert ( & key , & value , & old_value ) ; Ok ( old_value ) } , Format :: Bin ( before_write_callback , _ ) => { let mut block = bin_file_block_of_insert ( & key , & value , & mut self . cfg . integrity ) ? ; let old_value = self . map . insert ( key . clone ( ) , value . clone ( ) ) ; if let Some ( f ) = before_write_callback { f ( & mut block ) ; } if let Some ( f ) = before_write_callback { f ( & mut block ) ; } self . file_worker . write_bytes ( block ) ; self . update_index_when_insert ( & key , & value , & old_value ) ; Ok ( old_value ) } , } }
Inserts a key-value pair into the map.
Inserts a key - value pair into the map .
&mut self
key
Key
value
Value
&mut self
key
Key
value
Value
errors
Error can by returned only if serde_json::to_string() return error:
Serialization can fail if 'Key' or 'Value' s implementation of `Serialize` decides to
fail, or if 'Key' or 'Value' contains a map with non-string keys.
Error can by returned only if serde_json :: to_string () return error : Serialization can fail if ' Key ' or ' Value ' s implementation of ` Serialize ` decides to fail or if ' Key ' or ' Value ' contains a map with non - string keys .