diff --git a/src/api.rs b/src/api.rs index ddc0368..99f3b7b 100644 --- a/src/api.rs +++ b/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 { - let mut cookies = request.guard::().unwrap(); + let mut cookies = request.guard::>().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::>>() { + let db = match request.guard::>>() { 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 { - let db = request.guard::>>()?; + let db = request.guard::>>()?; match user::count::(&db) { Err(_) => return Outcome::Failure((Status::InternalServerError, ())), @@ -166,7 +166,7 @@ pub struct InitialSetup { } #[get("/initial_setup")] -fn initial_setup(db: State>) -> Result, errors::Error> { +fn initial_setup(db: State<'_, Arc>) -> Result, errors::Error> { let initial_setup = InitialSetup { has_any_users: user::count::(&db)? > 0, }; @@ -175,7 +175,7 @@ fn initial_setup(db: State>) -> Result, errors::Error #[get("/settings")] fn get_settings( - db: State>, + db: State<'_, Arc>, _admin_rights: AdminRights, ) -> Result, errors::Error> { let config = config::read::(&db)?; @@ -184,7 +184,7 @@ fn get_settings( #[put("/settings", data = "")] fn put_settings( - db: State>, + db: State<'_, Arc>, _admin_rights: AdminRights, config: Json, ) -> Result<(), errors::Error> { @@ -193,14 +193,14 @@ fn put_settings( } #[get("/preferences")] -fn get_preferences(db: State>, auth: Auth) -> Result, errors::Error> { +fn get_preferences(db: State<'_, Arc>, auth: Auth) -> Result, errors::Error> { let preferences = config::read_preferences::(&db, &auth.username)?; Ok(Json(preferences)) } #[put("/preferences", data = "")] fn put_preferences( - db: State>, + db: State<'_, Arc>, auth: Auth, preferences: Json, ) -> Result<(), errors::Error> { @@ -210,7 +210,7 @@ fn put_preferences( #[post("/trigger_index")] fn trigger_index( - command_sender: State>, + command_sender: State<'_, Arc>, _admin_rights: AdminRights, ) -> Result<(), errors::Error> { command_sender.trigger_reindex()?; @@ -230,9 +230,9 @@ struct AuthOutput { #[post("/auth", data = "")] fn auth( - db: State>, + db: State<'_, Arc>, credentials: Json, - mut cookies: Cookies, + mut cookies: Cookies<'_>, ) -> Result, errors::Error> { if !user::auth::(&db, &credentials.username, &credentials.password)? { bail!(errors::ErrorKind::IncorrectCredentials) @@ -248,7 +248,7 @@ fn auth( #[get("/browse")] fn browse_root( - db: State>, + db: State<'_, Arc>, _auth: Auth, ) -> Result>, errors::Error> { let result = index::browse(db.deref().deref(), &PathBuf::new())?; @@ -257,7 +257,7 @@ fn browse_root( #[get("/browse/")] fn browse( - db: State>, + db: State<'_, Arc>, _auth: Auth, path: VFSPathBuf, ) -> Result>, errors::Error> { @@ -266,14 +266,14 @@ fn browse( } #[get("/flatten")] -fn flatten_root(db: State>, _auth: Auth) -> Result>, errors::Error> { +fn flatten_root(db: State<'_, Arc>, _auth: Auth) -> Result>, errors::Error> { let result = index::flatten(db.deref().deref(), &PathBuf::new())?; Ok(Json(result)) } #[get("/flatten/")] fn flatten( - db: State>, + db: State<'_, Arc>, _auth: Auth, path: VFSPathBuf, ) -> Result>, errors::Error> { @@ -282,20 +282,20 @@ fn flatten( } #[get("/random")] -fn random(db: State>, _auth: Auth) -> Result>, errors::Error> { +fn random(db: State<'_, Arc>, _auth: Auth) -> Result>, errors::Error> { let result = index::get_random_albums(db.deref().deref(), 20)?; Ok(Json(result)) } #[get("/recent")] -fn recent(db: State>, _auth: Auth) -> Result>, errors::Error> { +fn recent(db: State<'_, Arc>, _auth: Auth) -> Result>, errors::Error> { let result = index::get_recent_albums(db.deref().deref(), 20)?; Ok(Json(result)) } #[get("/search")] fn search_root( - db: State>, + db: State<'_, Arc>, _auth: Auth, ) -> Result>, errors::Error> { let result = index::search(db.deref().deref(), "")?; @@ -304,7 +304,7 @@ fn search_root( #[get("/search/")] fn search( - db: State>, + db: State<'_, Arc>, _auth: Auth, query: String, ) -> Result>, errors::Error> { @@ -314,7 +314,7 @@ fn search( #[get("/serve/")] fn serve( - db: State>, + db: State<'_, Arc>, _auth: Auth, path: VFSPathBuf, ) -> Result, errors::Error> { @@ -339,7 +339,7 @@ pub struct ListPlaylistsEntry { #[get("/playlists")] fn list_playlists( - db: State>, + db: State<'_, Arc>, auth: Auth, ) -> Result>, errors::Error> { let playlist_names = playlist::list_playlists(&auth.username, db.deref().deref())?; @@ -358,7 +358,7 @@ pub struct SavePlaylistInput { #[put("/playlist/", data = "")] fn save_playlist( - db: State>, + db: State<'_, Arc>, auth: Auth, name: String, playlist: Json, @@ -369,7 +369,7 @@ fn save_playlist( #[get("/playlist/")] fn read_playlist( - db: State>, + db: State<'_, Arc>, auth: Auth, name: String, ) -> Result>, errors::Error> { @@ -378,14 +378,14 @@ fn read_playlist( } #[delete("/playlist/")] -fn delete_playlist(db: State>, auth: Auth, name: String) -> Result<(), errors::Error> { +fn delete_playlist(db: State<'_, Arc>, auth: Auth, name: String) -> Result<(), errors::Error> { playlist::delete_playlist(&name, &auth.username, db.deref().deref())?; Ok(()) } #[put("/lastfm/now_playing/")] fn lastfm_now_playing( - db: State>, + db: State<'_, Arc>, auth: Auth, path: VFSPathBuf, ) -> Result<(), errors::Error> { @@ -394,14 +394,14 @@ fn lastfm_now_playing( } #[post("/lastfm/scrobble/")] -fn lastfm_scrobble(db: State>, auth: Auth, path: VFSPathBuf) -> Result<(), errors::Error> { +fn lastfm_scrobble(db: State<'_, Arc>, auth: Auth, path: VFSPathBuf) -> Result<(), errors::Error> { lastfm::scrobble(db.deref().deref(), &auth.username, &path.into() as &PathBuf)?; Ok(()) } #[get("/lastfm/link?&")] fn lastfm_link( - db: State>, + db: State<'_, Arc>, auth: Auth, token: String, content: String, @@ -430,7 +430,7 @@ fn lastfm_link( } #[delete("/lastfm/link")] -fn lastfm_unlink(db: State>, auth: Auth) -> Result<(), errors::Error> { +fn lastfm_unlink(db: State<'_, Arc>, auth: Auth) -> Result<(), errors::Error> { lastfm::unlink(db.deref().deref(), &auth.username)?; Ok(()) } diff --git a/src/db/mod.rs b/src/db/mod.rs index 5a2a80b..899c5a7 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -17,7 +17,7 @@ const DB_MIGRATIONS_PATH: &str = "migrations"; embed_migrations!("migrations"); pub trait ConnectionSource { - fn get_connection(&self) -> MutexGuard; + fn get_connection(&self) -> MutexGuard<'_, SqliteConnection>; fn get_connection_mutex(&self) -> Arc>; } @@ -75,7 +75,7 @@ impl DB { } impl ConnectionSource for DB { - fn get_connection(&self) -> MutexGuard { + fn get_connection(&self) -> MutexGuard<'_, SqliteConnection> { self.connection.lock().unwrap() } diff --git a/src/errors.rs b/src/errors.rs index 3c933a6..8d8c4ec 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -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 { diff --git a/src/index.rs b/src/index.rs index dac7f08..6a80544 100644 --- a/src/index.rs +++ b/src/index.rs @@ -169,7 +169,7 @@ impl<'conn> IndexBuilder<'conn> { fn new( connection: &Mutex, album_art_pattern: Regex, - ) -> Result { + ) -> Result, errors::Error> { let mut new_songs = Vec::new(); let mut new_directories = Vec::new(); new_songs.reserve_exact(INDEX_BUILDING_INSERT_BUFFER_SIZE); diff --git a/src/main.rs b/src/main.rs index e3bbd21..c640685 100644 --- a/src/main.rs +++ b/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; diff --git a/src/serve.rs b/src/serve.rs index 2d1215a..70ca21b 100644 --- a/src/serve.rs +++ b/src/serve.rs @@ -44,7 +44,7 @@ impl<'r, R: Responder<'r>> RangeResponder { RangeResponder { original } } - fn ignore_range(self, request: &rocket::request::Request, file_length: Option) -> response::Result<'r> { + fn ignore_range(self, request: &rocket::request::Request<'_>, file_length: Option) -> 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) -> Option } impl<'r> Responder<'r> for RangeResponder { - 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 = metadata.map(|m| m.len()); diff --git a/src/swagger.rs b/src/swagger.rs index 32e7850..103da80 100644 --- a/src/swagger.rs +++ b/src/swagger.rs @@ -15,7 +15,7 @@ pub fn get_routes() -> Vec { } #[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("/", rank = 9)] -fn files(static_dirs: State>, file: PathBuf) -> Option { +fn files(static_dirs: State<'_, Arc>, file: PathBuf) -> Option { let path = static_dirs.swagger_dir_path.clone().join(file.clone()); NamedFile::open(path).ok() } diff --git a/src/web.rs b/src/web.rs index b935b71..09da8e0 100644 --- a/src/web.rs +++ b/src/web.rs @@ -14,14 +14,14 @@ pub fn get_routes() -> Vec { } #[get("/", rank = 10)] -fn index(static_dirs: State>) -> io::Result { +fn index(static_dirs: State<'_, Arc>) -> io::Result { let mut path = static_dirs.web_dir_path.clone(); path.push("index.html"); NamedFile::open(path) } #[get("/", rank = 10)] -fn files(static_dirs: State>, file: PathBuf) -> Option { +fn files(static_dirs: State<'_, Arc>, file: PathBuf) -> Option { let path = static_dirs.web_dir_path.clone().join(file.clone()); NamedFile::open(path).ok() }