#compose #container #proc-macro #deserialize

macro compose_spec_macros

Procedural macros for use in the compose_spec crate

2 releases

0.1.1 Oct 16, 2024
0.1.0 Apr 5, 2024

#1528 in Procedural macros

Download history 26/week @ 2024-08-16 36/week @ 2024-08-23 35/week @ 2024-08-30 39/week @ 2024-09-06 45/week @ 2024-09-13 89/week @ 2024-09-20 88/week @ 2024-09-27 76/week @ 2024-10-04 197/week @ 2024-10-11 140/week @ 2024-10-18 56/week @ 2024-10-25 65/week @ 2024-11-01 43/week @ 2024-11-08 49/week @ 2024-11-15 60/week @ 2024-11-22 36/week @ 2024-11-29

195 downloads per month
Used in 2 crates (via compose_spec)

MPL-2.0 license

94KB
1.5K SLoC

compose_spec

Crates.io Version Crates.io MSRV docs.rs License GitHub Actions CI Workflow Status

compose_spec is a Rust library crate for (de)serializing from/to the Compose specification.

compose_spec strives for:

  • Idiomatic Rust 🦀
    • Uses semantically appropriate types from the standard library like PathBuf and Duration.
  • Correctness
    • Values are fully validated and parsed.
    • Enums are used for fields which conflict with each other. For example, in services, network_mode and networks are combined into network_config.
  • Ease of use
    • Fully documented, though the documentation could be fleshed out more with examples and explanations, help in this regard would be appreciated!
    • Helpful functions such as conversion between short and long syntax forms of values with multiple representations (e.g. build and ports).

See the documentation for more details.

Examples

use compose_spec::{Compose, Service, service::Image};

let yaml = "\
services:
  caddy:
    image: docker.io/library/caddy:latest
    ports:
      - 8000:80
      - 8443:443
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy-data:/data
volumes:
  caddy-data:
";

// Deserialize `Compose`
let compose: Compose = serde_yaml::from_str(yaml)?;

// Serialize `Compose`
let value = serde_yaml::to_value(&compose)?;

// Get the `Image` of the "caddy" service
let caddy: Option<&Service> = compose.services.get("caddy");
let image: &Option<Image> = &caddy.unwrap().image;
let image: &Image = image.as_ref().unwrap();

assert_eq!(image, "docker.io/library/caddy:latest");
assert_eq!(image.name(), "docker.io/library/caddy");
assert_eq!(image.tag(), Some("latest"));

Minimum Supported Rust Version (MSRV)

The minimum version of the Rust compiler compose_spec can currently compile with is 1.70, which is tested in CI. Increasing the MSRV is not considered to be a breaking change.

Contribution

Contributions, suggestions, and/or comments are appreciated! Feel free to create an issue, discussion, or pull request. Generally, it is preferable to start a discussion for a feature request or open an issue for reporting a bug before submitting changes with a pull request.

Project Layout

compose_spec is composed of two packages set up in a Cargo workspace. The root package, compose_spec, is the main library. The other package, compose_spec_macros, located in a directory of the same name, is a procedural macro library used in compose_spec. compose_spec_macros is not designed to be used outside the compose_spec library.

Local CI

If you are submitting code changes in a pull request and would like to run the CI jobs locally, use the following commands:

  • format: cargo fmt --check --all
  • clippy: cargo clippy --workspace --tests
  • test: cargo test --workspace -- --include-ignored
  • doc: cargo doc --workspace --document-private-items
  • docs-rs:
    • Install the nightly Rust toolchain, rustup toolchain install nightly.
    • Install cargo-docs-rs.
    • cargo docs-rs
  • spellcheck:
  • msrv:
  • minimal-versions:
    • Install the nightly Rust toolchain, rustup toolchain install nightly.
    • Install cargo-hack.
    • Install cargo-minimal-versions.
    • cargo minimal-versions check --workspace
    • cargo minimal-versions test --workspace
  • semver-checks:

License

All source code for compose_spec is licensed under the Mozilla Public License v2.0. View the LICENSE file for more information.

The Compose specification itself is licensed under the Apache License v2.0. See that project's LICENSE file for more information.

Dependencies

~230–670KB
~16K SLoC