scaleway-rs 0.2.7

A pure Rust scaleway API binding.
Documentation
use std::collections::HashMap;
use serde::Deserialize;

/// Raw API response from the list-volume-types endpoint.
///
/// The Scaleway API returns volume types as a map keyed by type ID (e.g. `"b_ssd"`, `"l_ssd"`),
/// rather than an array. This struct mirrors that shape for deserialization; the map entries are
/// then flattened into [`ScalewayVolumeType`] values for public use.
#[derive(Deserialize, Debug)]
pub struct ScalewayVolumeTypeRoot {
    pub volumes: HashMap<String, ScalewayVolumeTypeItem>,
}

/// A single volume type entry as returned by the API, without its type ID.
///
/// The ID is the map key in [`ScalewayVolumeTypeRoot::volumes`] and is merged into
/// [`ScalewayVolumeType`] after deserialization.
#[derive(Deserialize, Debug)]
pub struct ScalewayVolumeTypeItem {
    pub display_name: String,
    pub capabilities: ScalewayVolumeTypeCapabilities,
    pub constraints: ScalewayVolumeTypeConstraints,
}

/// Flags describing what operations a volume type supports.
#[derive(Deserialize, Debug)]
pub struct ScalewayVolumeTypeCapabilities {
    /// Whether volumes of this type can be snapshotted.
    pub snapshot: bool,
}

/// Size constraints for volumes of a given type, in bytes.
#[derive(Deserialize, Debug)]
pub struct ScalewayVolumeTypeConstraints {
    pub min: u64,
    pub max: u64,
}

/// A Scaleway block storage volume type, as returned by [`crate::Scaleway::list_volume_types`].
///
/// This is a flattened view of [`ScalewayVolumeTypeItem`] with the type ID (the map key from the
/// raw API response) promoted to a named field.
#[derive(Deserialize, Debug)]
pub struct ScalewayVolumeType {
    /// The type identifier, e.g. `"b_ssd"` or `"l_ssd"`.
    pub id: String,
    pub display_name: String,
    pub capabilities: ScalewayVolumeTypeCapabilities,
    pub constraints: ScalewayVolumeTypeConstraints,
}