tree-wide: use 'dyn' for all trait objects

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2019-06-07 13:10:56 +02:00
parent e993db91cd
commit dd5495d6dc
26 changed files with 83 additions and 81 deletions

View File

@ -37,7 +37,7 @@ fn authenticate_user(username: &str, password: &str) -> Result<(), Error> {
fn create_ticket(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let username = tools::required_string_param(&param, "username")?;

View File

@ -56,7 +56,7 @@ fn mark_selections<F: Fn(DateTime<Local>, &BackupInfo) -> String> (
fn list_groups(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let store = param["store"].as_str().unwrap();
@ -91,7 +91,7 @@ fn list_groups(
fn list_snapshot_files (
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let store = tools::required_string_param(&param, "store")?;
@ -112,7 +112,7 @@ fn list_snapshot_files (
fn delete_snapshots (
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let store = tools::required_string_param(&param, "store")?;
@ -132,7 +132,7 @@ fn delete_snapshots (
fn list_snapshots (
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let store = tools::required_string_param(&param, "store")?;
@ -164,7 +164,7 @@ fn list_snapshots (
fn prune(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let store = param["store"].as_str().unwrap();
@ -272,7 +272,7 @@ fn api_method_prune() -> ApiMethod {
fn start_garbage_collection(
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let store = param["store"].as_str().unwrap().to_string();
@ -304,7 +304,7 @@ pub fn api_method_start_garbage_collection() -> ApiMethod {
fn garbage_collection_status(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let store = param["store"].as_str().unwrap();
@ -329,7 +329,7 @@ pub fn api_method_garbage_collection_status() -> ApiMethod {
fn get_backup_list(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
//let config = datastore::config()?;
@ -359,7 +359,7 @@ fn get_backup_list(
fn get_datastore_list(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let config = datastore::config()?;

View File

@ -51,7 +51,7 @@ fn upload_pxar(
req_body: Body,
param: Value,
_info: &ApiAsyncMethod,
rpcenv: Box<RpcEnvironment>,
rpcenv: Box<dyn RpcEnvironment>,
) -> Result<BoxFut, Error> {
let store = tools::required_string_param(&param, "store")?;
@ -150,7 +150,7 @@ fn download_pxar(
_req_body: Body,
param: Value,
_info: &ApiAsyncMethod,
_rpcenv: Box<RpcEnvironment>,
_rpcenv: Box<dyn RpcEnvironment>,
) -> Result<BoxFut, Error> {
let store = tools::required_string_param(&param, "store")?;

View File

@ -48,7 +48,7 @@ fn upgrade_to_backup_protocol(
req_body: Body,
param: Value,
_info: &ApiAsyncMethod,
rpcenv: Box<RpcEnvironment>,
rpcenv: Box<dyn RpcEnvironment>,
) -> Result<BoxFut, Error> {
let debug = param["debug"].as_bool().unwrap_or(false);
@ -213,7 +213,7 @@ pub fn api_method_create_dynamic_index() -> ApiMethod {
fn create_dynamic_index(
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let env: &BackupEnvironment = rpcenv.as_ref();
@ -252,7 +252,7 @@ pub fn api_method_create_fixed_index() -> ApiMethod {
fn create_fixed_index(
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let env: &BackupEnvironment = rpcenv.as_ref();
@ -306,7 +306,7 @@ pub fn api_method_dynamic_append() -> ApiMethod {
fn dynamic_append (
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let wid = tools::required_integer_param(&param, "wid")? as usize;
@ -359,7 +359,7 @@ pub fn api_method_fixed_append() -> ApiMethod {
fn fixed_append (
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let wid = tools::required_integer_param(&param, "wid")? as usize;
@ -408,7 +408,7 @@ pub fn api_method_close_dynamic_index() -> ApiMethod {
fn close_dynamic_index (
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let wid = tools::required_integer_param(&param, "wid")? as usize;
@ -444,7 +444,7 @@ pub fn api_method_close_fixed_index() -> ApiMethod {
fn close_fixed_index (
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let wid = tools::required_integer_param(&param, "wid")? as usize;
@ -463,7 +463,7 @@ fn close_fixed_index (
fn finish_backup (
_param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let env: &BackupEnvironment = rpcenv.as_ref();
@ -491,7 +491,7 @@ fn dynamic_chunk_index(
_req_body: Body,
param: Value,
_info: &ApiAsyncMethod,
rpcenv: Box<RpcEnvironment>,
rpcenv: Box<dyn RpcEnvironment>,
) -> Result<BoxFut, Error> {
let env: &BackupEnvironment = rpcenv.as_ref();
@ -564,7 +564,7 @@ fn fixed_chunk_index(
_req_body: Body,
param: Value,
_info: &ApiAsyncMethod,
rpcenv: Box<RpcEnvironment>,
rpcenv: Box<dyn RpcEnvironment>,
) -> Result<BoxFut, Error> {
let env: &BackupEnvironment = rpcenv.as_ref();

View File

@ -440,12 +440,13 @@ impl RpcEnvironment for BackupEnvironment {
}
}
impl AsRef<BackupEnvironment> for RpcEnvironment {
impl AsRef<BackupEnvironment> for dyn RpcEnvironment {
fn as_ref(&self) -> &BackupEnvironment {
self.as_any().downcast_ref::<BackupEnvironment>().unwrap()
}
}
impl AsRef<BackupEnvironment> for Box<RpcEnvironment> {
impl AsRef<BackupEnvironment> for Box<dyn RpcEnvironment> {
fn as_ref(&self) -> &BackupEnvironment {
self.as_any().downcast_ref::<BackupEnvironment>().unwrap()
}

View File

@ -86,7 +86,7 @@ impl hyper::service::Service for BackupService {
type ReqBody = Body;
type ResBody = Body;
type Error = Error;
type Future = Box<Future<Item = Response<Body>, Error = Self::Error> + Send>;
type Future = Box<dyn Future<Item = Response<Body>, Error = Self::Error> + Send>;
fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future {
let path = req.uri().path().to_owned();

View File

@ -74,7 +74,7 @@ fn upload_fixed_chunk(
req_body: Body,
param: Value,
_info: &ApiAsyncMethod,
rpcenv: Box<RpcEnvironment>,
rpcenv: Box<dyn RpcEnvironment>,
) -> Result<BoxFut, Error> {
let wid = tools::required_integer_param(&param, "wid")? as usize;
@ -121,7 +121,7 @@ fn upload_dynamic_chunk(
req_body: Body,
param: Value,
_info: &ApiAsyncMethod,
rpcenv: Box<RpcEnvironment>,
rpcenv: Box<dyn RpcEnvironment>,
) -> Result<BoxFut, Error> {
let wid = tools::required_integer_param(&param, "wid")? as usize;
@ -160,7 +160,7 @@ fn upload_speedtest(
req_body: Body,
_param: Value,
_info: &ApiAsyncMethod,
rpcenv: Box<RpcEnvironment>,
rpcenv: Box<dyn RpcEnvironment>,
) -> Result<BoxFut, Error> {
let resp = req_body
@ -203,7 +203,7 @@ fn upload_config(
req_body: Body,
param: Value,
_info: &ApiAsyncMethod,
rpcenv: Box<RpcEnvironment>,
rpcenv: Box<dyn RpcEnvironment>,
) -> Result<BoxFut, Error> {
let mut file_name = tools::required_string_param(&param, "file-name")?.to_owned();

View File

@ -18,7 +18,7 @@ pub fn get() -> ApiMethod {
fn get_datastore_list(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let config = datastore::config()?;
@ -38,7 +38,7 @@ pub fn post() -> ApiMethod {
fn create_datastore(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
// fixme: locking ?
@ -75,7 +75,7 @@ pub fn delete() -> ApiMethod {
fn delete_datastore(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
println!("This is a test {}", param);

View File

@ -54,7 +54,7 @@ fn read_etc_resolv_conf() -> Result<Value, Error> {
fn update_dns(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
lazy_static! {
@ -100,7 +100,7 @@ fn update_dns(
fn get_dns(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
read_etc_resolv_conf()

View File

@ -10,7 +10,7 @@ use crate::api2::types::*;
fn get_network_config(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
Ok(json!({}))

View File

@ -94,7 +94,7 @@ fn json_service_state(service: &str, status: Value) -> Value {
fn list_services(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let mut list = vec![];
@ -117,7 +117,7 @@ fn list_services(
fn get_service_state(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let service = tools::required_string_param(&param, "service")?;
@ -162,7 +162,7 @@ fn run_service_command(service: &str, cmd: &str) -> Result<Value, Error> {
fn start_service(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let service = tools::required_string_param(&param, "service")?;
@ -175,7 +175,7 @@ fn start_service(
fn stop_service(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let service = tools::required_string_param(&param, "service")?;
@ -188,7 +188,7 @@ fn stop_service(
fn restart_service(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let service = tools::required_string_param(&param, "service")?;
@ -206,7 +206,7 @@ fn restart_service(
fn reload_service(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let service = tools::required_string_param(&param, "service")?;

View File

@ -76,7 +76,7 @@ fn dump_journal(
fn get_syslog(
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let (count, lines) = dump_journal(

View File

@ -14,7 +14,7 @@ use crate::server::{self, UPID};
fn get_task_status(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let upid = extract_upid(&param)?;
@ -56,7 +56,7 @@ fn extract_upid(param: &Value) -> Result<UPID, Error> {
fn read_task_log(
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let upid = extract_upid(&param)?;
@ -96,7 +96,7 @@ fn read_task_log(
fn stop_task(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let upid = extract_upid(&param)?;
@ -111,7 +111,7 @@ fn stop_task(
fn list_tasks(
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let start = param["start"].as_u64().unwrap_or(0);

View File

@ -35,7 +35,7 @@ fn read_etc_localtime() -> Result<String, Error> {
fn get_time(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let datetime = Local::now();
@ -53,7 +53,7 @@ fn get_time(
fn set_timezone(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let timezone = tools::required_string_param(&param, "timezone")?;

View File

@ -9,7 +9,7 @@ use serde_json::{json, Value};
fn get_subscription(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let url = "https://www.proxmox.com/en/proxmox-backup-server/pricing";

View File

@ -11,7 +11,7 @@ const PROXMOX_PKG_REPOID: &'static str = env!("PROXMOX_PKG_REPOID");
fn get_version(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
Ok(json!({