Skip to main content

Crate any2nix

Crate any2nix 

Source
Expand description

This crate provides simple functions for translating different formats to Nix.

They serve as higher-level options to serialization functions.

Due to being based on serialization, the translation process has a chance to fail, primarily on invalid formatting.

§Usage

This crate is on crates.io and can be added as a dependency of your project:

cargo add any2nix

§Supported Formats

See Format for an enumeration of supported formats.

Each format is gated behind its own feature.

The default feature enables all formats.

§Crate Features

Besides the features for each format, this crate also exposes the following features:

  • clap: Enables command-line argument parsing through [clap].
  • utoipa: Enables OpenAPI schema generation through [utoipa].

§Examples: TOML

let some_toml = r#"
[package]
name = "any2nix"
"#;
// Functions follow a clear "{format}_to_nix" naming convention.
let nix = match any2nix::toml_to_nix(some_toml) {
    Ok(v) => v,
    Err(e) => panic!("invalid TOML") // Returns a "Result<String, any2nix::Error>".
};

println!("{}", nix);
// Output:
//
// {
//   package = {
//     name = "any2nix";
//   };
// }

Enums§

Error
Aggregator of all errors from all used serializers (translators) for simpler error handling.
Format
Enumeration of the currently supported formats for conversion.

Functions§

ini_to_nix
Translates text in INI to Nix.
json_to_nix
Translates text in JSON to Nix.
toml_to_nix
Translates text in TOML to Nix.
yaml_to_nix
Translates text in YAML to Nix.