use rocket::response::status::BadRequest; use serde_json::json; pub mod album; pub mod artist; pub mod track; pub mod user; // todo : rework api type ApiError = BadRequest; type FallibleApiResponse = Result; pub fn api_error(msg: &str) -> ApiError { BadRequest(json!({ "error": msg })) } pub trait ToAPI: Sized { /// Generate public API JSON fn api(&self) -> impl std::future::Future; } pub async fn to_api(albums: &[impl ToAPI]) -> Vec { let mut ret = Vec::new(); for e in albums { ret.push(e.api().await); } ret }