[PATCH proxmox v2 08/25] disks: gate api macro behind 'api-types' feature

Lukas Wagner
2026-03-19T09:47:12Z

Some users of this crate don't need the derived API types, so it is best
to gate it behind a feature.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
Tested-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
proxmox-disks/Cargo.toml | 6 +++++-
proxmox-disks/src/lib.rs | 18 ++++++++++--------
proxmox-disks/src/smart.rs | 9 +++++----
3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/proxmox-disks/Cargo.toml b/proxmox-disks/Cargo.toml
index 29bf56fe..f581e464 100644
--- a/proxmox-disks/Cargo.toml
+++ b/proxmox-disks/Cargo.toml
@@ -26,5 +26,9 @@ proxmox-io.workspace = true
proxmox-lang.workspace = true
proxmox-log.workspace = true
proxmox-parallel-handler.workspace = true
-proxmox-schema = { workspace = true, features = [ "api-macro", "api-types" ] }
+proxmox-schema = { workspace = true, features = [ "api-types" ], optional = true }
proxmox-sys.workspace = true
+
+[features]
+default = [ "dep:proxmox-schema" ]
+api-types = [ "proxmox-schema/api-macro" ]
diff --git a/proxmox-disks/src/lib.rs b/proxmox-disks/src/lib.rs
index 4039b4cd..74907711 100644
--- a/proxmox-disks/src/lib.rs
+++ b/proxmox-disks/src/lib.rs
@@ -17,13 +17,15 @@ use ::serde::{Deserialize, Serialize};
use proxmox_lang::{io_bail, io_format_err};
use proxmox_log::info;
use proxmox_parallel_handler::ParallelHandler;
-use proxmox_schema::api;
use proxmox_sys::linux::procfs::{mountinfo::Device, MountInfo};

use proxmox_schema::api_types::{
BLOCKDEVICE_DISK_AND_PARTITION_NAME_REGEX, BLOCKDEVICE_NAME_REGEX, UUID_REGEX,
};

+#[cfg(feature = "api-types")]
+use proxmox_schema::api;
+
mod zfs;
pub use zfs::*;
mod zpool_status;
@@ -626,7 +628,7 @@ impl Disk {
}
}

-#[api()]
+#[cfg_attr(feature = "api-types", api)]
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// This is just a rough estimate for a "type" of disk.
@@ -682,7 +684,7 @@ fn get_file_system_devices(lsblk_info: &[LsblkInfo]) -> Result<HashSet<u64>, Err
Ok(device_set)
}

-#[api()]
+#[cfg_attr(feature = "api-types", api)]
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
/// What a block device partition is used for.
@@ -703,7 +705,7 @@ pub enum PartitionUsageType {
FileSystem,
}

-#[api()]
+#[cfg_attr(feature = "api-types", api)]
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
/// What a block device (disk) is used for.
@@ -724,7 +726,7 @@ pub enum DiskUsageType {
FileSystem,
}

-#[api()]
+#[cfg_attr(feature = "api-types", api)]
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
/// Basic information about a partition
@@ -747,7 +749,7 @@ pub struct PartitionInfo {
pub uuid: Option<String>,
}

-#[api(
+#[cfg_attr(feature = "api-types", api(
properties: {
used: {
type: DiskUsageType,
@@ -765,7 +767,7 @@ pub struct PartitionInfo {
}
}
}
-)]
+))]
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
/// Information about how a Disk is used
@@ -1302,7 +1304,7 @@ pub fn create_single_linux_partition(disk: &Disk) -> Result<Disk, Error> {
}
}

-#[api()]
+#[cfg_attr(feature = "api-types", api)]
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
/// A file system type supported by our tooling.
diff --git a/proxmox-disks/src/smart.rs b/proxmox-disks/src/smart.rs
index 1d41cee2..247bc4d3 100644
--- a/proxmox-disks/src/smart.rs
+++ b/proxmox-disks/src/smart.rs
@@ -7,9 +7,10 @@ use std::{
use ::serde::{Deserialize, Serialize};
use anyhow::Error;

+#[cfg(feature = "api-types")]
use proxmox_schema::api;

-#[api()]
+#[cfg_attr(feature = "api-types", api)]
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// SMART status
@@ -22,7 +23,7 @@ pub enum SmartStatus {
Unknown,
}

-#[api()]
+#[cfg_attr(feature = "api-types", api)]
#[derive(Debug, Serialize, Deserialize)]
/// SMART Attribute
pub struct SmartAttribute {
@@ -51,7 +52,7 @@ pub struct SmartAttribute {
threshold: Option<f64>,
}

-#[api(
+#[cfg_attr(feature = "api-types", api(
properties: {
status: {
type: SmartStatus,
@@ -69,7 +70,7 @@ pub struct SmartAttribute {
},
},
},
-)]
+))]
#[derive(Debug, Serialize, Deserialize)]
/// Data from smartctl
pub struct SmartData {
--
2.47.3