digitalocean_api/api/size.rs
1use super::{ApiLinks, ApiMeta};
2use super::{HasPagination, HasResponse, HasValue};
3use crate::method::List;
4use crate::request::Request;
5use crate::request::SizeRequest;
6use crate::{ROOT_URL, STATIC_URL_ERROR};
7use getset::{Getters, Setters};
8use serde::Deserialize;
9use serde::Serialize;
10use url::Url;
11
12const SIZES_SEGMENT: &str = "sizes";
13
14/// The sizes objects represent different packages of hardware resources that
15/// can be used for Droplets. When a Droplet is created, a size must be
16/// selected so that the correct resources can be allocated.
17///
18/// Each size represents a plan that bundles together specific sets of
19/// resources. This includes the amount of RAM, the number of virtual CPUs,
20/// disk space, and transfer. The size object also includes the pricing
21/// details and the regions that the size is available in.
22///
23/// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#sizes)
24#[derive(Deserialize, Serialize, Debug, Clone, Getters, Setters)]
25#[get = "pub"]
26pub struct Size {
27 /// A human-readable string that is used to uniquely identify each size.
28 slug: String,
29
30 /// This is a boolean value that represents whether new Droplets can be
31 /// created with this size.
32 available: bool,
33
34 /// The amount of transfer bandwidth that is available for Droplets created
35 /// in this size. This only counts traffic on the public interface. The
36 /// value is given in terabytes.
37 transfer: f64,
38
39 /// This attribute describes the monthly cost of this Droplet size if the
40 /// Droplet is kept for an entire month. The value is measured in US
41 /// dollars.
42 price_monthly: f64,
43
44 /// This describes the price of the Droplet size as measured hourly. The
45 /// value is measured in US dollars.
46 price_hourly: f64,
47
48 /// The amount of RAM allocated to Droplets created of this size. The value
49 /// is represented in megabytes.
50 memory: usize,
51
52 /// The number of virtual CPUs allocated to Droplets of this size.
53 vcpus: usize,
54
55 /// The amount of disk space set aside for Droplets of this size. The value
56 /// is represented in gigabytes.
57 disk: usize,
58
59 /// An array containing the region slugs where this size is available for
60 /// Droplet creates.
61 regions: Vec<String>,
62}
63
64impl Size {
65 /// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#list-all-images)
66 pub fn list() -> SizeRequest<List, Vec<Size>> {
67 let mut url = ROOT_URL.clone();
68 url.path_segments_mut()
69 .expect(STATIC_URL_ERROR)
70 .push(SIZES_SEGMENT);
71
72 Request::new(url)
73 }
74}
75
76// There is no signular size return.
77
78/// Response type returned from Digital Ocean.
79#[derive(Deserialize, Serialize, Debug, Clone)]
80pub struct SizeListResponse {
81 sizes: Vec<Size>,
82 links: ApiLinks,
83 meta: ApiMeta,
84}
85
86impl HasResponse for Vec<Size> {
87 type Response = SizeListResponse;
88}
89
90impl HasPagination for SizeListResponse {
91 fn next_page(&self) -> Option<Url> {
92 self.links.next()
93 }
94}
95
96impl HasValue for SizeListResponse {
97 type Value = Vec<Size>;
98
99 fn value(self) -> Vec<Size> {
100 self.sizes
101 }
102}