mirror of
https://github.com/Drop-OSS/dropbreak.git
synced 2026-07-18 09:57:53 -04:00
Retab
Execute retab! on all files to expand tabs into spaces.
This commit is contained in:
+3
-3
@@ -6,9 +6,9 @@ quick_error! {
|
||||
pub enum BreakError {
|
||||
/// An error returned when doing file operations, this might happen by opening, closing,
|
||||
/// locking or flushing
|
||||
Io(err: ::std::io::Error) {
|
||||
from()
|
||||
}
|
||||
Io(err: ::std::io::Error) {
|
||||
from()
|
||||
}
|
||||
/// This error happens if Bincode cannot deserialize a given file. If you get this error
|
||||
/// check your database is not corrupt. (This includes non-empty files **not** created by
|
||||
/// RustBreak!
|
||||
|
||||
+7
-7
@@ -104,7 +104,7 @@ pub type BreakResult<T> = Result<T, BreakError>;
|
||||
/// ];
|
||||
///
|
||||
/// for (album, artist) in albums {
|
||||
/// db.insert(&format!("album_{}",album), artist).unwrap();
|
||||
/// db.insert(&format!("album_{}",album), artist).unwrap();
|
||||
/// }
|
||||
/// db.flush().unwrap();
|
||||
/// ```
|
||||
@@ -133,20 +133,20 @@ impl<T: Serialize + Deserialize + Eq + Hash> Database<T> {
|
||||
/// ];
|
||||
///
|
||||
/// for (album, artist) in albums {
|
||||
/// db.insert(&format!("album_{}",album), artist).unwrap();
|
||||
/// db.insert(&format!("album_{}",album), artist).unwrap();
|
||||
/// }
|
||||
/// db.flush().unwrap();
|
||||
/// ```
|
||||
pub fn open<P: AsRef<Path>>(path: P) -> BreakResult<Database<T>> {
|
||||
use std::fs::OpenOptions;
|
||||
use fs2::FileExt;
|
||||
use std::fs::OpenOptions;
|
||||
use fs2::FileExt;
|
||||
use std::io::Read;
|
||||
use bincode::serde::deserialize;
|
||||
|
||||
let mut file = try!(OpenOptions::new().read(true).write(true).create(true).open(path));
|
||||
try!(file.try_lock_exclusive());
|
||||
let mut file = try!(OpenOptions::new().read(true).write(true).create(true).open(path));
|
||||
try!(file.try_lock_exclusive());
|
||||
|
||||
let mut buf = Vec::new();
|
||||
let mut buf = Vec::new();
|
||||
try!(file.read_to_end(&mut buf));
|
||||
let map : HashMap<T, Vec<u8>> = if !buf.is_empty() {
|
||||
try!(deserialize(&buf))
|
||||
|
||||
Reference in New Issue
Block a user