Giter VIP home page Giter VIP logo

oci-spec's Introduction

oci-spec

oci-spec at crates.io oci-spec at docs.rs

oci-spec is a library for Serialize/Deserialize oci-runtime-spec and oci-image-spec config.

Usage

Deserialize oci-runtime-spec

Use load of Spec to deserialize oci-runtime-spec config.

If it is a required item in oci-runtime-spec but there is no value in JSON, an error will occur. Also if there is no JSON value in the optional item in oci-runtime-spec, None will be set.

For example, ociVersion is a required item in oci-runtime-spec, but if ociVersion does not exist in JSON, an error occurs.

Although root is an object type and internally has a required path, no error occurs even if there is no value in JSON. However, if root has a value in JSON and the value of the required item held internally is not in JSON, an error occurs.

Example:

extern crate oci_spec;

use oci_spec::runtime::Spec;

fn main() {
    // Deserialize oci runtime specification config.
    let spec = match Spec::load("config.json") {
        Ok(s) => s,
        Err(e) => panic!("{}", e),
    }
    println!("oci-runtime-spec version is {}", spec.version);
}

Serialize oci-runtime-spec

Use save of Spec to serialize oci runtime spec config.

If the type is Option and the value is None, it is not serialized.

Example:

extern crate oci_spec;

use oci_spec::runtime::Spec;

fn main() {
    // Deserialize oci runtime specification config.
    let spec = match Spec::load("config.json") {
        Ok(s) => s,
        Err(e) => panic!("{}", e),
    }
    
    // Serialize oci runtime specification config.
    match Spec::save(&spec, "config.json") {
        Ok(_) => {},
        Err(e) => panic!("{}", e),
    }
}

License

oci-spec is under the MIT or Apache-2.0 license.

oci-spec's People

Contributors

smiyaguchi avatar

Stargazers

fanjiyun avatar Kim Ko avatar Toshiki Teramura avatar DDDDOGE avatar Djordje Lukic avatar krircc avatar

Forkers

jts22

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.