add some doc comments

This commit is contained in:
2021-02-21 12:52:22 +01:00
parent 78966796fc
commit 2b510dfda4
5 changed files with 405 additions and 325 deletions
+42 -29
View File
@@ -10,7 +10,7 @@ use std::ops::Deref;
use std::path::PathBuf;
use actix_session::CookieSession;
use actix_web::{App, HttpResponse, HttpServer, web};
use actix_web::{web, App, HttpResponse, HttpServer};
use actix_web_static_files;
use actix_web_static_files::ResourceFiles as StaticFiles;
use clap::Arg;
@@ -108,29 +108,40 @@ const DEF_ADDRESS: &str = "127.0.0.1:8080";
async fn main() -> std::io::Result<()> {
let def_addr_help = format!("Set custom server address, default {}", DEF_ADDRESS);
let app = clap::App::new("yopa")
.arg(Arg::with_name("version")
.long("version")
.short("V")
.help("Show version and exit"))
.arg(Arg::with_name("verbose")
.short("v")
.multiple(true)
.help("Increase verbosity of logging"))
.arg(Arg::with_name("address")
.short("a")
.takes_value(true)
.help(&def_addr_help))
.arg(Arg::with_name("json")
.long("json")
.short("j")
.help("Use JSON storage format instead of binary"))
.arg(Arg::with_name("file")
.help("Database file to use"));
.arg(
Arg::with_name("version")
.long("version")
.short("V")
.help("Show version and exit"),
)
.arg(
Arg::with_name("verbose")
.short("v")
.multiple(true)
.help("Increase verbosity of logging"),
)
.arg(
Arg::with_name("address")
.short("a")
.takes_value(true)
.help(&def_addr_help),
)
.arg(
Arg::with_name("json")
.long("json")
.short("j")
.help("Use JSON storage format instead of binary"),
)
.arg(Arg::with_name("file").help("Database file to use"));
let matches = app.get_matches();
if matches.is_present("version") {
println!("yopa-web {}, using yopa {}", env!("CARGO_PKG_VERSION"), yopa::VERSION);
println!(
"yopa-web {}, using yopa {}",
env!("CARGO_PKG_VERSION"),
yopa::VERSION
);
return Ok(());
}
@@ -147,7 +158,11 @@ async fn main() -> std::io::Result<()> {
let json = matches.is_present("json");
let file = matches.value_of("file").unwrap_or(if json { "yopa-store.json" } else { "yopa-store.dat" });
let file = matches.value_of("file").unwrap_or(if json {
"yopa-store.json"
} else {
"yopa-store.dat"
});
let file_path = if file.starts_with('/') {
std::env::current_dir()?.join(file)
@@ -157,14 +172,12 @@ async fn main() -> std::io::Result<()> {
debug!("Using database file: {}", file_path.display());
let mut store = if json {
let store = if json {
Storage::new_json(file_path)
} else {
Storage::new_bincode(file_path)
};
store.load()
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
}
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
let yopa_store: YopaStoreWrapper = web::Data::new(tokio::sync::RwLock::new(store));
@@ -223,7 +236,7 @@ async fn main() -> std::io::Result<()> {
HttpResponse::NotFound().body("File or endpoint not found")
}))
})
.bind(server_address)?
.run()
.await
.bind(server_address)?
.run()
.await
}
+1 -1
View File
@@ -1,5 +1,5 @@
use actix_session::Session;
use actix_web::{web, Responder, HttpResponse};
use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};
use yopa::model::{ObjectModel, PropertyModel};
+1 -1
View File
@@ -85,7 +85,7 @@ fn prepare_object_create_data(rg: &Storage, model_id: ID) -> actix_web::Result<O
.get_property_models_for_parents(prop_object_ids)
.collect(),
},
objects: rg.get_objects_of_type(related_ids).collect(),
objects: rg.get_objects_of_types(related_ids).collect(),
})
}
+1 -3
View File
@@ -46,9 +46,7 @@ pub enum ActixErrorWrapper {
Storage(#[from] StorageError),
}
impl ResponseError for ActixErrorWrapper {
}
impl ResponseError for ActixErrorWrapper {}
pub trait StorageErrorIntoResponseError<T> {
fn err_to_500(self) -> Result<T, ActixErrorWrapper>;