forked from Proxmox/proxmox
apt-api-types: use serde-plain to display/parse enums
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
parent
b11dbfd105
commit
960131925e
@ -9,7 +9,7 @@ exclude.workspace = true
|
||||
description = "APT API type definitions."
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_plain.workspace = true
|
||||
proxmox-schema = { workspace = true, features = ["api-macro"] }
|
||||
proxmox-config-digest.workspace = true
|
||||
|
@ -6,12 +6,12 @@ Build-Depends: debhelper (>= 12),
|
||||
cargo:native <!nocheck>,
|
||||
rustc:native <!nocheck>,
|
||||
libstd-rust-dev <!nocheck>,
|
||||
librust-anyhow-1+default-dev <!nocheck>,
|
||||
librust-proxmox-config-digest-0.1+default-dev <!nocheck>,
|
||||
librust-proxmox-schema-3+api-macro-dev (>= 3.1.1-~~) <!nocheck>,
|
||||
librust-proxmox-schema-3+default-dev (>= 3.1.1-~~) <!nocheck>,
|
||||
librust-serde-1+default-dev <!nocheck>,
|
||||
librust-serde-1+derive-dev <!nocheck>
|
||||
librust-serde-1+derive-dev <!nocheck>,
|
||||
librust-serde-plain-1+default-dev <!nocheck>
|
||||
Maintainer: Proxmox Support Team <support@proxmox.com>
|
||||
Standards-Version: 4.6.2
|
||||
Vcs-Git: git://git.proxmox.com/git/proxmox-apt.git
|
||||
@ -24,12 +24,12 @@ Architecture: any
|
||||
Multi-Arch: same
|
||||
Depends:
|
||||
${misc:Depends},
|
||||
librust-anyhow-1+default-dev,
|
||||
librust-proxmox-config-digest-0.1+default-dev,
|
||||
librust-proxmox-schema-3+api-macro-dev (>= 3.1.1-~~),
|
||||
librust-proxmox-schema-3+default-dev (>= 3.1.1-~~),
|
||||
librust-serde-1+default-dev,
|
||||
librust-serde-1+derive-dev
|
||||
librust-serde-1+derive-dev,
|
||||
librust-serde-plain-1+default-dev
|
||||
Provides:
|
||||
librust-proxmox-apt-api-types+default-dev (= ${binary:Version}),
|
||||
librust-proxmox-apt-api-types-1-dev (= ${binary:Version}),
|
||||
|
@ -1,6 +1,5 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use anyhow::{bail, Error};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use proxmox_config_digest::ConfigDigest;
|
||||
@ -16,26 +15,8 @@ pub enum APTRepositoryFileType {
|
||||
Sources,
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for APTRepositoryFileType {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(file_type: &str) -> Result<Self, Error> {
|
||||
match file_type {
|
||||
"list" => Ok(APTRepositoryFileType::List),
|
||||
"sources" => Ok(APTRepositoryFileType::Sources),
|
||||
_ => bail!("invalid file type '{file_type}'"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for APTRepositoryFileType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
APTRepositoryFileType::List => write!(f, "list"),
|
||||
APTRepositoryFileType::Sources => write!(f, "sources"),
|
||||
}
|
||||
}
|
||||
}
|
||||
serde_plain::derive_display_from_serialize!(APTRepositoryFileType);
|
||||
serde_plain::derive_fromstr_from_deserialize!(APTRepositoryFileType);
|
||||
|
||||
#[api]
|
||||
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
@ -47,26 +28,8 @@ pub enum APTRepositoryPackageType {
|
||||
DebSrc,
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for APTRepositoryPackageType {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(package_type: &str) -> Result<Self, Error> {
|
||||
match package_type {
|
||||
"deb" => Ok(APTRepositoryPackageType::Deb),
|
||||
"deb-src" => Ok(APTRepositoryPackageType::DebSrc),
|
||||
_ => bail!("invalid package type '{package_type}'"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for APTRepositoryPackageType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
APTRepositoryPackageType::Deb => write!(f, "deb"),
|
||||
APTRepositoryPackageType::DebSrc => write!(f, "deb-src"),
|
||||
}
|
||||
}
|
||||
}
|
||||
serde_plain::derive_display_from_serialize!(APTRepositoryPackageType);
|
||||
serde_plain::derive_fromstr_from_deserialize!(APTRepositoryPackageType);
|
||||
|
||||
#[api(
|
||||
properties: {
|
||||
@ -327,6 +290,9 @@ pub enum APTRepositoryHandle {
|
||||
CephReefTest,
|
||||
}
|
||||
|
||||
serde_plain::derive_display_from_serialize!(APTRepositoryHandle);
|
||||
serde_plain::derive_fromstr_from_deserialize!(APTRepositoryHandle);
|
||||
|
||||
#[api()]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
|
Loading…
Reference in New Issue
Block a user