2018 edition idioms
This commit is contained in:
parent
b70c8ff622
commit
57ded63cb8
8 changed files with 38 additions and 67 deletions
56
src/api.rs
56
src/api.rs
|
@ -71,7 +71,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Auth {
|
|||
type Error = ();
|
||||
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, ()> {
|
||||
let mut cookies = request.guard::<Cookies>().unwrap();
|
||||
let mut cookies = request.guard::<Cookies<'_>>().unwrap();
|
||||
if let Some(u) = cookies.get_private(COOKIE_SESSION) {
|
||||
return Outcome::Success(Auth {
|
||||
username: u.value().to_string(),
|
||||
|
@ -85,7 +85,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Auth {
|
|||
password: Some(password),
|
||||
}) = Basic::from_str(auth_header_string.trim_start_matches("Basic "))
|
||||
{
|
||||
let db = match request.guard::<State<Arc<DB>>>() {
|
||||
let db = match request.guard::<State<'_, Arc<DB>>>() {
|
||||
Outcome::Success(d) => d,
|
||||
_ => return Outcome::Failure((Status::InternalServerError, ())),
|
||||
};
|
||||
|
@ -107,7 +107,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for AdminRights {
|
|||
type Error = ();
|
||||
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, ()> {
|
||||
let db = request.guard::<State<Arc<DB>>>()?;
|
||||
let db = request.guard::<State<'_, Arc<DB>>>()?;
|
||||
|
||||
match user::count::<DB>(&db) {
|
||||
Err(_) => return Outcome::Failure((Status::InternalServerError, ())),
|
||||
|
@ -166,7 +166,7 @@ pub struct InitialSetup {
|
|||
}
|
||||
|
||||
#[get("/initial_setup")]
|
||||
fn initial_setup(db: State<Arc<DB>>) -> Result<Json<InitialSetup>, errors::Error> {
|
||||
fn initial_setup(db: State<'_, Arc<DB>>) -> Result<Json<InitialSetup>, errors::Error> {
|
||||
let initial_setup = InitialSetup {
|
||||
has_any_users: user::count::<DB>(&db)? > 0,
|
||||
};
|
||||
|
@ -175,7 +175,7 @@ fn initial_setup(db: State<Arc<DB>>) -> Result<Json<InitialSetup>, errors::Error
|
|||
|
||||
#[get("/settings")]
|
||||
fn get_settings(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
_admin_rights: AdminRights,
|
||||
) -> Result<Json<Config>, errors::Error> {
|
||||
let config = config::read::<DB>(&db)?;
|
||||
|
@ -184,7 +184,7 @@ fn get_settings(
|
|||
|
||||
#[put("/settings", data = "<config>")]
|
||||
fn put_settings(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
_admin_rights: AdminRights,
|
||||
config: Json<Config>,
|
||||
) -> Result<(), errors::Error> {
|
||||
|
@ -193,14 +193,14 @@ fn put_settings(
|
|||
}
|
||||
|
||||
#[get("/preferences")]
|
||||
fn get_preferences(db: State<Arc<DB>>, auth: Auth) -> Result<Json<Preferences>, errors::Error> {
|
||||
fn get_preferences(db: State<'_, Arc<DB>>, auth: Auth) -> Result<Json<Preferences>, errors::Error> {
|
||||
let preferences = config::read_preferences::<DB>(&db, &auth.username)?;
|
||||
Ok(Json(preferences))
|
||||
}
|
||||
|
||||
#[put("/preferences", data = "<preferences>")]
|
||||
fn put_preferences(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
auth: Auth,
|
||||
preferences: Json<Preferences>,
|
||||
) -> Result<(), errors::Error> {
|
||||
|
@ -210,7 +210,7 @@ fn put_preferences(
|
|||
|
||||
#[post("/trigger_index")]
|
||||
fn trigger_index(
|
||||
command_sender: State<Arc<index::CommandSender>>,
|
||||
command_sender: State<'_, Arc<index::CommandSender>>,
|
||||
_admin_rights: AdminRights,
|
||||
) -> Result<(), errors::Error> {
|
||||
command_sender.trigger_reindex()?;
|
||||
|
@ -230,9 +230,9 @@ struct AuthOutput {
|
|||
|
||||
#[post("/auth", data = "<credentials>")]
|
||||
fn auth(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
credentials: Json<AuthCredentials>,
|
||||
mut cookies: Cookies,
|
||||
mut cookies: Cookies<'_>,
|
||||
) -> Result<Json<AuthOutput>, errors::Error> {
|
||||
if !user::auth::<DB>(&db, &credentials.username, &credentials.password)? {
|
||||
bail!(errors::ErrorKind::IncorrectCredentials)
|
||||
|
@ -248,7 +248,7 @@ fn auth(
|
|||
|
||||
#[get("/browse")]
|
||||
fn browse_root(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
_auth: Auth,
|
||||
) -> Result<Json<Vec<index::CollectionFile>>, errors::Error> {
|
||||
let result = index::browse(db.deref().deref(), &PathBuf::new())?;
|
||||
|
@ -257,7 +257,7 @@ fn browse_root(
|
|||
|
||||
#[get("/browse/<path>")]
|
||||
fn browse(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
_auth: Auth,
|
||||
path: VFSPathBuf,
|
||||
) -> Result<Json<Vec<index::CollectionFile>>, errors::Error> {
|
||||
|
@ -266,14 +266,14 @@ fn browse(
|
|||
}
|
||||
|
||||
#[get("/flatten")]
|
||||
fn flatten_root(db: State<Arc<DB>>, _auth: Auth) -> Result<Json<Vec<index::Song>>, errors::Error> {
|
||||
fn flatten_root(db: State<'_, Arc<DB>>, _auth: Auth) -> Result<Json<Vec<index::Song>>, errors::Error> {
|
||||
let result = index::flatten(db.deref().deref(), &PathBuf::new())?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
#[get("/flatten/<path>")]
|
||||
fn flatten(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
_auth: Auth,
|
||||
path: VFSPathBuf,
|
||||
) -> Result<Json<Vec<index::Song>>, errors::Error> {
|
||||
|
@ -282,20 +282,20 @@ fn flatten(
|
|||
}
|
||||
|
||||
#[get("/random")]
|
||||
fn random(db: State<Arc<DB>>, _auth: Auth) -> Result<Json<Vec<index::Directory>>, errors::Error> {
|
||||
fn random(db: State<'_, Arc<DB>>, _auth: Auth) -> Result<Json<Vec<index::Directory>>, errors::Error> {
|
||||
let result = index::get_random_albums(db.deref().deref(), 20)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
#[get("/recent")]
|
||||
fn recent(db: State<Arc<DB>>, _auth: Auth) -> Result<Json<Vec<index::Directory>>, errors::Error> {
|
||||
fn recent(db: State<'_, Arc<DB>>, _auth: Auth) -> Result<Json<Vec<index::Directory>>, errors::Error> {
|
||||
let result = index::get_recent_albums(db.deref().deref(), 20)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
#[get("/search")]
|
||||
fn search_root(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
_auth: Auth,
|
||||
) -> Result<Json<Vec<index::CollectionFile>>, errors::Error> {
|
||||
let result = index::search(db.deref().deref(), "")?;
|
||||
|
@ -304,7 +304,7 @@ fn search_root(
|
|||
|
||||
#[get("/search/<query>")]
|
||||
fn search(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
_auth: Auth,
|
||||
query: String,
|
||||
) -> Result<Json<Vec<index::CollectionFile>>, errors::Error> {
|
||||
|
@ -314,7 +314,7 @@ fn search(
|
|||
|
||||
#[get("/serve/<path>")]
|
||||
fn serve(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
_auth: Auth,
|
||||
path: VFSPathBuf,
|
||||
) -> Result<serve::RangeResponder<File>, errors::Error> {
|
||||
|
@ -339,7 +339,7 @@ pub struct ListPlaylistsEntry {
|
|||
|
||||
#[get("/playlists")]
|
||||
fn list_playlists(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
auth: Auth,
|
||||
) -> Result<Json<Vec<ListPlaylistsEntry>>, errors::Error> {
|
||||
let playlist_names = playlist::list_playlists(&auth.username, db.deref().deref())?;
|
||||
|
@ -358,7 +358,7 @@ pub struct SavePlaylistInput {
|
|||
|
||||
#[put("/playlist/<name>", data = "<playlist>")]
|
||||
fn save_playlist(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
auth: Auth,
|
||||
name: String,
|
||||
playlist: Json<SavePlaylistInput>,
|
||||
|
@ -369,7 +369,7 @@ fn save_playlist(
|
|||
|
||||
#[get("/playlist/<name>")]
|
||||
fn read_playlist(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
auth: Auth,
|
||||
name: String,
|
||||
) -> Result<Json<Vec<index::Song>>, errors::Error> {
|
||||
|
@ -378,14 +378,14 @@ fn read_playlist(
|
|||
}
|
||||
|
||||
#[delete("/playlist/<name>")]
|
||||
fn delete_playlist(db: State<Arc<DB>>, auth: Auth, name: String) -> Result<(), errors::Error> {
|
||||
fn delete_playlist(db: State<'_, Arc<DB>>, auth: Auth, name: String) -> Result<(), errors::Error> {
|
||||
playlist::delete_playlist(&name, &auth.username, db.deref().deref())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[put("/lastfm/now_playing/<path>")]
|
||||
fn lastfm_now_playing(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
auth: Auth,
|
||||
path: VFSPathBuf,
|
||||
) -> Result<(), errors::Error> {
|
||||
|
@ -394,14 +394,14 @@ fn lastfm_now_playing(
|
|||
}
|
||||
|
||||
#[post("/lastfm/scrobble/<path>")]
|
||||
fn lastfm_scrobble(db: State<Arc<DB>>, auth: Auth, path: VFSPathBuf) -> Result<(), errors::Error> {
|
||||
fn lastfm_scrobble(db: State<'_, Arc<DB>>, auth: Auth, path: VFSPathBuf) -> Result<(), errors::Error> {
|
||||
lastfm::scrobble(db.deref().deref(), &auth.username, &path.into() as &PathBuf)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[get("/lastfm/link?<token>&<content>")]
|
||||
fn lastfm_link(
|
||||
db: State<Arc<DB>>,
|
||||
db: State<'_, Arc<DB>>,
|
||||
auth: Auth,
|
||||
token: String,
|
||||
content: String,
|
||||
|
@ -430,7 +430,7 @@ fn lastfm_link(
|
|||
}
|
||||
|
||||
#[delete("/lastfm/link")]
|
||||
fn lastfm_unlink(db: State<Arc<DB>>, auth: Auth) -> Result<(), errors::Error> {
|
||||
fn lastfm_unlink(db: State<'_, Arc<DB>>, auth: Auth) -> Result<(), errors::Error> {
|
||||
lastfm::unlink(db.deref().deref(), &auth.username)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ const DB_MIGRATIONS_PATH: &str = "migrations";
|
|||
embed_migrations!("migrations");
|
||||
|
||||
pub trait ConnectionSource {
|
||||
fn get_connection(&self) -> MutexGuard<SqliteConnection>;
|
||||
fn get_connection(&self) -> MutexGuard<'_, SqliteConnection>;
|
||||
fn get_connection_mutex(&self) -> Arc<Mutex<SqliteConnection>>;
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ impl DB {
|
|||
}
|
||||
|
||||
impl ConnectionSource for DB {
|
||||
fn get_connection(&self) -> MutexGuard<SqliteConnection> {
|
||||
fn get_connection(&self) -> MutexGuard<'_, SqliteConnection> {
|
||||
self.connection.lock().unwrap()
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ error_chain! {
|
|||
}
|
||||
|
||||
impl<'r> rocket::response::Responder<'r> for Error {
|
||||
fn respond_to(self, _: &rocket::request::Request) -> rocket::response::Result<'r> {
|
||||
fn respond_to(self, _: &rocket::request::Request<'_>) -> rocket::response::Result<'r> {
|
||||
let mut build = rocket::response::Response::build();
|
||||
build
|
||||
.status(match self.0 {
|
||||
|
|
|
@ -169,7 +169,7 @@ impl<'conn> IndexBuilder<'conn> {
|
|||
fn new(
|
||||
connection: &Mutex<SqliteConnection>,
|
||||
album_art_pattern: Regex,
|
||||
) -> Result<IndexBuilder, errors::Error> {
|
||||
) -> Result<IndexBuilder<'_>, errors::Error> {
|
||||
let mut new_songs = Vec::new();
|
||||
let mut new_directories = Vec::new();
|
||||
new_songs.reserve_exact(INDEX_BUILDING_INSERT_BUFFER_SIZE);
|
||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -2,47 +2,18 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
#![allow(proc_macro_derive_resolution_fallback)]
|
||||
|
||||
extern crate ape;
|
||||
extern crate app_dirs;
|
||||
extern crate base64;
|
||||
extern crate core;
|
||||
extern crate crypto;
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
#[macro_use]
|
||||
extern crate diesel_migrations;
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
extern crate getopts;
|
||||
extern crate id3;
|
||||
extern crate image;
|
||||
extern crate lewton;
|
||||
extern crate metaflac;
|
||||
extern crate mp3_duration;
|
||||
extern crate rand;
|
||||
extern crate regex;
|
||||
extern crate reqwest;
|
||||
extern crate ring;
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
extern crate rocket_contrib;
|
||||
extern crate rustfm_scrobble;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate serde_json;
|
||||
extern crate toml;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate simplelog;
|
||||
|
||||
#[cfg(windows)]
|
||||
extern crate uuid;
|
||||
#[cfg(windows)]
|
||||
extern crate winapi;
|
||||
|
||||
#[cfg(unix)]
|
||||
extern crate unix_daemonize;
|
||||
|
||||
#[cfg(unix)]
|
||||
use std::fs::File;
|
||||
|
|
|
@ -44,7 +44,7 @@ impl<'r, R: Responder<'r>> RangeResponder<R> {
|
|||
RangeResponder { original }
|
||||
}
|
||||
|
||||
fn ignore_range(self, request: &rocket::request::Request, file_length: Option<u64>) -> response::Result<'r> {
|
||||
fn ignore_range(self, request: &rocket::request::Request<'_>, file_length: Option<u64>) -> response::Result<'r> {
|
||||
let mut response = self.original.respond_to(request)?;
|
||||
if let Some(content_length) = file_length {
|
||||
response.set_header(ContentLength(content_length));
|
||||
|
@ -99,7 +99,7 @@ fn truncate_range(range: &PartialFileRange, file_length: &Option<u64>) -> Option
|
|||
}
|
||||
|
||||
impl<'r> Responder<'r> for RangeResponder<File> {
|
||||
fn respond_to(mut self, request: &rocket::request::Request) -> response::Result<'r> {
|
||||
fn respond_to(mut self, request: &rocket::request::Request<'_>) -> response::Result<'r> {
|
||||
|
||||
let metadata: Option<_> = self.original.metadata().ok();
|
||||
let file_length: Option<u64> = metadata.map(|m| m.len());
|
||||
|
|
|
@ -15,7 +15,7 @@ pub fn get_routes() -> Vec<rocket::Route> {
|
|||
}
|
||||
|
||||
#[get("/", rank = 9)]
|
||||
fn index(origin: &Origin) -> Redirect {
|
||||
fn index(origin: &Origin<'_>) -> Redirect {
|
||||
let mut new_path = origin.path().to_owned();
|
||||
if !new_path.ends_with("/") {
|
||||
new_path.push_str("/");
|
||||
|
@ -26,7 +26,7 @@ fn index(origin: &Origin) -> Redirect {
|
|||
}
|
||||
|
||||
#[get("/<file..>", rank = 9)]
|
||||
fn files(static_dirs: State<Arc<StaticDirs>>, file: PathBuf) -> Option<NamedFile> {
|
||||
fn files(static_dirs: State<'_, Arc<StaticDirs>>, file: PathBuf) -> Option<NamedFile> {
|
||||
let path = static_dirs.swagger_dir_path.clone().join(file.clone());
|
||||
NamedFile::open(path).ok()
|
||||
}
|
||||
|
|
|
@ -14,14 +14,14 @@ pub fn get_routes() -> Vec<rocket::Route> {
|
|||
}
|
||||
|
||||
#[get("/", rank = 10)]
|
||||
fn index(static_dirs: State<Arc<StaticDirs>>) -> io::Result<NamedFile> {
|
||||
fn index(static_dirs: State<'_, Arc<StaticDirs>>) -> io::Result<NamedFile> {
|
||||
let mut path = static_dirs.web_dir_path.clone();
|
||||
path.push("index.html");
|
||||
NamedFile::open(path)
|
||||
}
|
||||
|
||||
#[get("/<file..>", rank = 10)]
|
||||
fn files(static_dirs: State<Arc<StaticDirs>>, file: PathBuf) -> Option<NamedFile> {
|
||||
fn files(static_dirs: State<'_, Arc<StaticDirs>>, file: PathBuf) -> Option<NamedFile> {
|
||||
let path = static_dirs.web_dir_path.clone().join(file.clone());
|
||||
NamedFile::open(path).ok()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue