tree-wide: replace serde_json::from_value(a_value.clone())
`&Value` itself implements `Deserializer` and can therefore be passed directly to `T::deserialize` without requiring an intermediate `clone()`. (This also enables optionally borrowing strings if the result has a short enough lifetime) Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
845baef61b
commit
38774184a9
|
@ -22,6 +22,7 @@ percent-encoding = "2.1"
|
|||
pin-project-lite = "0.2"
|
||||
regex = "1.5"
|
||||
rustyline = "7"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "1.6", features = [ "fs", "signal" ] }
|
||||
tokio-stream = "0.1.0"
|
||||
|
|
|
@ -131,7 +131,7 @@ fn do_crypto_parameters(param: &Value, keep_keyfd_open: bool) -> Result<CryptoPa
|
|||
};
|
||||
|
||||
let mode: Option<CryptMode> = match param.get("crypt-mode") {
|
||||
Some(mode) => Some(serde_json::from_value(mode.clone())?),
|
||||
Some(mode) => Some(serde::Deserialize::deserialize(mode)?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ impl BackupManifest {
|
|||
pub fn fingerprint(&self) -> Result<Option<Fingerprint>, Error> {
|
||||
match &self.unprotected["key-fingerprint"] {
|
||||
Value::Null => Ok(None),
|
||||
value => Ok(Some(serde_json::from_value(value.clone())?))
|
||||
value => Ok(Some(Deserialize::deserialize(value)?))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ impl BackupManifest {
|
|||
|
||||
let fingerprint = &json["unprotected"]["key-fingerprint"];
|
||||
if fingerprint != &Value::Null {
|
||||
let fingerprint = serde_json::from_value(fingerprint.clone())?;
|
||||
let fingerprint = Fingerprint::deserialize(fingerprint)?;
|
||||
let config_fp = Fingerprint::new(crypt_config.fingerprint());
|
||||
if config_fp != fingerprint {
|
||||
bail!(
|
||||
|
|
|
@ -230,7 +230,7 @@ async fn list(snapshot: String, path: String, base64: bool, param: Value) -> Res
|
|||
keyfile,
|
||||
};
|
||||
let driver: Option<BlockDriverType> = match param.get("driver") {
|
||||
Some(drv) => Some(serde_json::from_value(drv.clone())?),
|
||||
Some(drv) => Some(serde::Deserialize::deserialize(drv)?),
|
||||
None => None,
|
||||
};
|
||||
data_list(driver, details, file, path).await
|
||||
|
@ -382,7 +382,7 @@ async fn extract(
|
|||
keyfile,
|
||||
};
|
||||
let driver: Option<BlockDriverType> = match param.get("driver") {
|
||||
Some(drv) => Some(serde_json::from_value(drv.clone())?),
|
||||
Some(drv) => Some(serde::Deserialize::deserialize(drv)?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ pub(crate) fn get_acme_plugin(
|
|||
|
||||
Ok(Some(match ty.as_str() {
|
||||
"dns" => {
|
||||
let plugin: DnsPlugin = serde_json::from_value(data.clone())?;
|
||||
let plugin: DnsPlugin = serde::Deserialize::deserialize(data)?;
|
||||
Box::new(plugin)
|
||||
}
|
||||
"standalone" => {
|
||||
|
|
|
@ -706,7 +706,7 @@ pub fn update_plugin(
|
|||
bail!("cannot update plugin of type {:?}", ty);
|
||||
}
|
||||
|
||||
let mut plugin: DnsPlugin = serde_json::from_value(entry.clone())?;
|
||||
let mut plugin = DnsPlugin::deserialize(&*entry)?;
|
||||
|
||||
if let Some(delete) = delete {
|
||||
for delete_prop in delete {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use anyhow::{Error, bail};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, to_value};
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission};
|
||||
|
@ -539,7 +539,7 @@ pub fn update_interface(
|
|||
let interface = config.lookup_mut(&iface)?;
|
||||
|
||||
if let Some(interface_type) = param.get("type") {
|
||||
let interface_type: NetworkInterfaceType = serde_json::from_value(interface_type.clone())?;
|
||||
let interface_type = NetworkInterfaceType::deserialize(interface_type)?;
|
||||
if interface_type != interface.interface_type {
|
||||
bail!("got unexpected interface type ({:?} != {:?})", interface_type, interface.interface_type);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use anyhow::Error;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
|
||||
use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
|
||||
|
@ -77,7 +78,7 @@ async fn list_media(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<(),
|
|||
};
|
||||
|
||||
fn render_status(_value: &Value, record: &Value) -> Result<String, Error> {
|
||||
let record: MediaListEntry = serde_json::from_value(record.clone())?;
|
||||
let record = MediaListEntry::deserialize(record)?;
|
||||
Ok(match record.status {
|
||||
MediaStatus::Damaged | MediaStatus::Retired => serde_json::to_value(&record.status)?
|
||||
.as_str()
|
||||
|
|
Loading…
Reference in New Issue