Commit d431c402 authored by Cyril Plisko's avatar Cyril Plisko

CpuOptions

parent 47b8bac9
Pipeline #81184299 failed with stage
in 3 minutes and 49 seconds
use serde::Serialize;
use crate::skip_serializing_if::SkipSerializingIf;
#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct BlockDeviceMapping {
......@@ -86,37 +88,6 @@ impl BlockDevice {
// "VolumeType" : String
//}
// Having `is_zero` as a standalone function upsets clippy due to passing
// trivial type by reference. So trait it is.
trait SkipSerializeIf {
fn is_zero(&self) -> bool {
false
}
fn is_true(&self) -> bool {
false
}
fn is_false(&self) -> bool {
false
}
}
impl SkipSerializeIf for u64 {
fn is_zero(&self) -> bool {
*self == 0
}
}
impl SkipSerializeIf for bool {
fn is_true(&self) -> bool {
*self
}
fn is_false(&self) -> bool {
!*self
}
}
#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Ebs {
......
use serde::Serialize;
use crate::skip_serializing_if::SkipSerializingIf;
#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CpuOptions {
core_count: u64,
threads_per_core: u64,
}
impl Default for CpuOptions {
fn default() -> Self {
Self {
core_count: 1,
threads_per_core: 1,
}
}
}
impl SkipSerializingIf for CpuOptions {
fn is_default(&self) -> bool {
*self == Self::default()
}
}
use serde::Serialize;
use crate::skip_serializing_if::SkipSerializingIf;
use super::BlockDeviceMapping;
use super::CpuOptions;
use super::InstanceType;
//{
......@@ -51,6 +54,7 @@ pub struct Instance {
affinity: String,
availability_zone: String,
block_device_mappings: Vec<BlockDeviceMapping>,
#[serde(skip_serializing_if = "CpuOptions::is_default")]
cpu_options: CpuOptions,
credit_specification: CreditSpecification,
disable_api_termination: bool,
......@@ -107,9 +111,6 @@ impl Instance {
}
}
#[derive(Clone, Debug, Default, Serialize)]
pub struct CpuOptions;
#[derive(Clone, Debug, Default, Serialize)]
pub struct CreditSpecification;
......
pub use blockdevice::{BlockDeviceMapping, Ebs};
pub use instance::{CpuOptions, CreditSpecification, Instance};
pub use cpu_options::CpuOptions;
pub use instance::{CreditSpecification, Instance};
pub use instance_type::InstanceType;
mod blockdevice;
......@@ -8,3 +9,5 @@ mod instance_type;
#[derive(Debug)]
pub struct Ec2;
mod cpu_options;
......@@ -32,6 +32,8 @@ pub mod parameter;
pub mod resource;
pub mod transform;
mod skip_serializing_if;
const AWS_TEMPLATE_FORMAT_VERSION: &str = "2010-09-09";
#[derive(Debug, Serialize)]
......
// Having `is_zero` as a standalone function upsets clippy due to passing
// trivial type by reference. So trait it is.
pub(crate) trait SkipSerializingIf {
fn is_default(&self) -> bool {
false
}
fn is_zero(&self) -> bool {
false
}
fn is_true(&self) -> bool {
false
}
fn is_false(&self) -> bool {
false
}
}
impl SkipSerializingIf for u64 {
fn is_zero(&self) -> bool {
*self == 0
}
}
impl SkipSerializingIf for bool {
fn is_true(&self) -> bool {
*self
}
fn is_false(&self) -> bool {
!*self
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment