Formatting
This commit is contained in:
parent
842514da85
commit
6339f94836
5 changed files with 69 additions and 71 deletions
|
@ -32,14 +32,14 @@ pub fn get_api_handler(collection: Arc<Mutex<Collection>>) -> Mount {
|
|||
mount.mount("/browse/", move |request: &mut Request| {
|
||||
let mut acquired_collection = collection.deref().lock().unwrap();
|
||||
self::browse(request, acquired_collection.deref_mut())
|
||||
} );
|
||||
});
|
||||
}
|
||||
{
|
||||
let collection = collection.clone();
|
||||
mount.mount("/flatten/", move |request: &mut Request| {
|
||||
let mut acquired_collection = collection.deref().lock().unwrap();
|
||||
self::flatten(request, acquired_collection.deref_mut())
|
||||
} );
|
||||
});
|
||||
}
|
||||
mount
|
||||
}
|
||||
|
|
|
@ -26,9 +26,7 @@ pub struct Collection {
|
|||
|
||||
impl Collection {
|
||||
pub fn new() -> Collection {
|
||||
Collection{
|
||||
vfs: Vfs::new(),
|
||||
}
|
||||
Collection { vfs: Vfs::new() }
|
||||
}
|
||||
|
||||
pub fn mount(&mut self, name: &str, real_path: &Path) -> Result<(), CollectionError> {
|
||||
|
@ -50,16 +48,13 @@ impl Collection {
|
|||
if file_meta.is_file() {
|
||||
let virtual_path = try!(self.vfs.real_to_virtual(file_path));
|
||||
let path_string = try!(virtual_path.to_str().ok_or(CollectionError::PathDecoding));
|
||||
let collection_file = CollectionFile::Song(Song {
|
||||
path: path_string.to_string(),
|
||||
});
|
||||
let collection_file = CollectionFile::Song(Song { path: path_string.to_string() });
|
||||
out.push(collection_file);
|
||||
} else if file_meta.is_dir() {
|
||||
let virtual_path = try!(self.vfs.real_to_virtual(file_path));
|
||||
let path_string = try!(virtual_path.to_str().ok_or(CollectionError::PathDecoding));
|
||||
let collection_file = CollectionFile::Directory(Directory {
|
||||
path: path_string.to_string(),
|
||||
});
|
||||
let collection_file =
|
||||
CollectionFile::Directory(Directory { path: path_string.to_string() });
|
||||
out.push(collection_file);
|
||||
}
|
||||
}
|
||||
|
|
15
src/error.rs
15
src/error.rs
|
@ -3,8 +3,7 @@ use std::fmt;
|
|||
use std::io;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CollectionError
|
||||
{
|
||||
pub enum CollectionError {
|
||||
PathDecoding,
|
||||
Io(io::Error),
|
||||
ConflictingMount,
|
||||
|
@ -22,7 +21,9 @@ impl error::Error for CollectionError {
|
|||
match *self {
|
||||
CollectionError::Io(ref err) => err.description(),
|
||||
CollectionError::PathDecoding => "Error while decoding a Path as a UTF-8 string",
|
||||
CollectionError::ConflictingMount => "Attempting to mount multiple directories under the same name",
|
||||
CollectionError::ConflictingMount => {
|
||||
"Attempting to mount multiple directories under the same name"
|
||||
}
|
||||
CollectionError::PathNotInVfs => "Requested path does not index a mount point",
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +43,12 @@ impl fmt::Display for CollectionError {
|
|||
match *self {
|
||||
CollectionError::Io(ref err) => write!(f, "IO error: {}", err),
|
||||
CollectionError::PathDecoding => write!(f, "Path decoding error"),
|
||||
CollectionError::ConflictingMount => write!(f, "Mount point already has a target directory"),
|
||||
CollectionError::PathNotInVfs => write!(f, "Requested path does not index a mount point"),
|
||||
CollectionError::ConflictingMount => {
|
||||
write!(f, "Mount point already has a target directory")
|
||||
}
|
||||
CollectionError::PathNotInVfs => {
|
||||
write!(f, "Requested path does not index a mount point")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ fn main() {
|
|||
let collection = Arc::new(Mutex::new(collection));
|
||||
|
||||
let mut mount = Mount::new();
|
||||
let api_handler = get_api_handler( collection );
|
||||
let api_handler = get_api_handler(collection);
|
||||
mount.mount("/static/", Static::new("samplemusic/"))
|
||||
.mount("/api/", api_handler);
|
||||
|
||||
|
|
|
@ -10,9 +10,7 @@ pub struct Vfs {
|
|||
|
||||
impl Vfs {
|
||||
pub fn new() -> Vfs {
|
||||
let instance = Vfs {
|
||||
mount_points: HashMap::new(),
|
||||
};
|
||||
let instance = Vfs { mount_points: HashMap::new() };
|
||||
instance
|
||||
}
|
||||
|
||||
|
@ -31,7 +29,7 @@ impl Vfs {
|
|||
Ok(p) => {
|
||||
let mount_path = Path::new(&name);
|
||||
return Ok(mount_path.join(p));
|
||||
},
|
||||
}
|
||||
Err(_) => (),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue