oci-spec is a library for Serialize/Deserialize oci-runtime-spec and oci-image-spec config.
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);
}
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),
}
}
oci-spec is under the MIT or Apache-2.0 license.