proxmox-rest-server: cleanup formatter, improve docs

Use trait for OutputFormatter. This is functionally equivalent,
but more rust-like...
This commit is contained in:
Dietmar Maurer
2021-09-27 12:59:06 +02:00
parent 8a23ea4656
commit 53daae8e89
8 changed files with 128 additions and 98 deletions

View File

@ -111,7 +111,7 @@ pub struct BackupEnvironment {
result_attributes: Value,
auth_id: Authid,
pub debug: bool,
pub formatter: &'static OutputFormatter,
pub formatter: &'static dyn OutputFormatter,
pub worker: Arc<WorkerTask>,
pub datastore: Arc<DataStore>,
pub backup_dir: BackupDir,
@ -146,7 +146,7 @@ impl BackupEnvironment {
worker,
datastore,
debug: false,
formatter: &JSON_FORMATTER,
formatter: JSON_FORMATTER,
backup_dir,
last_backup: None,
state: Arc::new(Mutex::new(state)),
@ -556,10 +556,7 @@ impl BackupEnvironment {
}
pub fn format_response(&self, result: Result<Value, Error>) -> Response<Body> {
match result {
Ok(data) => (self.formatter.format_data)(data, self),
Err(err) => (self.formatter.format_error)(err),
}
self.formatter.format_result(result, self)
}
/// Raise error if finished flag is not set