diff --git a/Cargo.lock b/Cargo.lock index a8569e8..7eb8c67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,7 +37,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "compose_spec" -version = "0.3.0-alpha.1" +version = "0.3.0-alpha.2" dependencies = [ "compose_spec_macros", "indexmap", diff --git a/Cargo.toml b/Cargo.toml index 9bdd1a2..633932a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -226,7 +226,7 @@ sort_commits = "oldest" [package] name = "compose_spec" -version = "0.3.0-alpha.1" +version = "0.3.0-alpha.2" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/src/common/short_or_long.rs b/src/common/short_or_long.rs index 302ef09..b218132 100644 --- a/src/common/short_or_long.rs +++ b/src/common/short_or_long.rs @@ -27,7 +27,7 @@ use crate::{ env_file, ports::{Port, ShortPort}, volumes::{Mount, ShortVolume}, - Build, ConfigOrSecret, Ulimit, + Build, ConfigOrSecret, Limit, Ulimit, }, Identifier, Include, }; @@ -249,6 +249,18 @@ impl From for ShortOrLong { } } +impl From> for ShortOrLong, L> { + fn from(value: Limit) -> Self { + Self::Short(value) + } +} + +impl From for ShortOrLong, L> { + fn from(value: u64) -> Self { + Limit::Value(value).into() + } +} + /// `impl From for ShortOrLong` and `impl From> for Type` macro_rules! impl_long_conversion { ($($t:ty),* $(,)?) => { diff --git a/src/service/limit.rs b/src/service/limit.rs index 81a5c0d..4afb5f5 100644 --- a/src/service/limit.rs +++ b/src/service/limit.rs @@ -32,6 +32,12 @@ impl From for Limit { } } +impl From for Limit { + fn from(value: u64) -> Self { + Self::Value(value) + } +} + impl From for Limit { fn from(value: ByteValue) -> Self { Self::Value(value) diff --git a/src/service/ulimit.rs b/src/service/ulimit.rs index 921488d..eee5e14 100644 --- a/src/service/ulimit.rs +++ b/src/service/ulimit.rs @@ -8,13 +8,15 @@ use thiserror::Error; use crate::{common::key_impls, AsShort, Extensions, ShortOrLong}; +use super::Limit; + /// Override the default ulimits for a [`Service`](super::Service) container. /// -/// Ulimits are defined as map from a [`Resource`] to either a singe limit ([`u64`]) or a mapping -/// of a soft and hard limit ([`Ulimit`]). +/// Ulimits are defined as map from a [`Resource`] to either a singe limit ([`Limit`]) or a +/// mapping of a soft and hard limit ([`Ulimit`]). /// /// [compose-spec](https://github.com/compose-spec/compose-spec/blob/master/05-services.md#ulimits) -pub type Ulimits = IndexMap>; +pub type Ulimits = IndexMap, Ulimit>>; /// [`Ulimit`] resource name (e.g. "nofile"). /// @@ -77,10 +79,10 @@ key_impls!(Resource => InvalidResourceError); #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] pub struct Ulimit { /// Soft limit. - pub soft: u64, + pub soft: Limit, /// Hard limit. - pub hard: u64, + pub hard: Limit, /// Extension values, which are (de)serialized via flattening. /// @@ -90,7 +92,7 @@ pub struct Ulimit { } impl AsShort for Ulimit { - type Short = u64; + type Short = Limit; fn as_short(&self) -> Option<&Self::Short> { let Self { @@ -105,6 +107,12 @@ impl AsShort for Ulimit { impl From for Ulimit { fn from(value: u64) -> Self { + Limit::Value(value).into() + } +} + +impl From> for Ulimit { + fn from(value: Limit) -> Self { Self { soft: value, hard: value, diff --git a/src/test-full.yaml b/src/test-full.yaml index ac796d1..2c0fd7a 100644 --- a/src/test-full.yaml +++ b/src/test-full.yaml @@ -84,6 +84,10 @@ services: soft: 100 hard: 200 x-test: test + unlimited: -1 + unlimitedlong: + soft: -1 + hard: -1 platforms: - linux/amd64 - linux/arm @@ -567,6 +571,10 @@ services: soft: 100 hard: 200 x-test: test + unlimited: -1 + unlimitedlong: + soft: -1 + hard: -1 user: user:group userns_mode: userns_mode volumes: