Crate basyx_rs

source ·
Expand description

A Rust library to work with Asset Administration Shells (AAS)

Examples

Creating a Submodel and Serialize to JSON

use basyx_rs::{DataTypeDefXsd, id_short_from_str};
use basyx_rs::prelude::*;
use std::io::Write;

let mut property = Property::new(DataTypeDefXsd::XsBoolean);
property.category = Some(format!("{}", Category::CONSTANT));

// id_short mandatory for all non-identifiable referables.
if let Some(id_short) = id_short_from_str("my_property1").ok() {
        property.id_short = Some(id_short);
   }

let sme = SubmodelElement::Property(property);

let mut submodel = Submodel::new("https://example.com/ids/1234567890".to_string());

submodel.add_submodel_element(sme.clone());

let json = serde_json::to_vec(&submodel);
let mut file = std::fs::OpenOptions::new()
    .create(true)
    .write(true)
    .read(true)
    .truncate(true)
    .open("submodel1.json");
let json = json.unwrap();
let buf: &[u8] = &json; // impl Deref for Vec<T> with Target = [T]
file.unwrap().write(buf);

Modules

Structs

Enums

Functions