Created
June 19, 2018 16:54
-
-
Save DoumanAsh/63cb693d1cd8095e5fe636147ffaa3e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///Modifies data via temporary serialization | |
| pub fn modify<F: FnOnce(&mut Data)>(&'de mut self, cb: F) -> io::Result<()> { | |
| let new_data: Vec<u8> = { | |
| let data = self.inner.as_slice(); | |
| let mut data = Ser::deserialize(data)?; | |
| cb(&mut data); | |
| Ser::serialize(&data)? | |
| }; | |
| if new_data.len() == 0 { | |
| Err(empty_write_error()) | |
| } else { | |
| self.inner.put_data(&new_data)?; | |
| self.inner.flush_sync() | |
| } | |
| } | |
| error[E0502]: cannot borrow `self.inner` as mutable because it is also borrowed as immutable | |
| --> src\serializer\mod.rs:149:13 | |
| | | |
| 138 | let data = self.inner.as_slice(); | |
| | ---------- immutable borrow occurs here | |
| ... | |
| 149 | self.inner.put_data(&new_data)?; | |
| | ^^^^^^^^^^ mutable borrow occurs here | |
| ... | |
| 152 | } | |
| | - immutable borrow ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment