Struct ruststep::ast::Record[][src]

pub struct Record {
    pub name: String,
    pub parameter: Parameter,
}
Expand description

A struct typed in EXPRESS schema, e.g. A(1.0, 2.0)

FromStr

use ruststep::ast::{Record, Parameter};
use std::str::FromStr;

let record = Record::from_str("A(1, 2)").unwrap();
assert_eq!(
    record,
    Record {
        name: "A".to_string(),
        parameter: vec![Parameter::Integer(1), Parameter::Integer(2)].into(),
    }
)

Deserialize as a map

serde::Deserializer implementation for Record provides a mapping it into “map” in serde data model. The keyword is mapped into the key and the parameters are its value:

use std::{str::FromStr, collections::HashMap};
use ruststep::ast::*;
use serde::Deserialize;

let p = Record::from_str("DATA_KEYWORD(1, 2)").unwrap();

// Map can be deserialize as a hashmap
assert_eq!(
    HashMap::<String, Vec<i32>>::deserialize(&p).unwrap(),
    maplit::hashmap! {
        "DATA_KEYWORD".to_string() => vec![1, 2]
    }
);

// Map in serde can be interpreted as Rust field
#[derive(Debug, Clone, PartialEq, Deserialize)]
struct X {
    #[serde(rename = "DATA_KEYWORD")]
    a: Vec<i32>,
}
assert_eq!(
    X::deserialize(&p).unwrap(),
    X { a: vec![1, 2] }
);

Mapping to simple instance

It is deserialized as a “struct” only when the hint function serde::Deserializer::deserialize_struct is called and the struct name matches to its keyword appears in the exchange structure. See the manual of container attribute in serde for detail.

use std::{str::FromStr, collections::HashMap};
use ruststep::ast::*;
use serde::Deserialize;

let p = Record::from_str("DATA_KEYWORD(1, 2)").unwrap();

#[derive(Debug, Clone, PartialEq, Deserialize)]
#[serde(rename = "DATA_KEYWORD")] // keyword matches
struct A {
    x: i32,
    y: i32,
}
assert_eq!(
    A::deserialize(&p).unwrap(),
    A { x: 1, y: 2 }
);

#[derive(Debug, Clone, PartialEq, Deserialize)]
#[serde(rename = "ANOTHER_KEYWORD")] // keyword does not match
struct B {
    x: i32,
    y: i32,
}
assert!(B::deserialize(&p).is_err());

Internal mapping to complex entity instance

Complex entity in EXPRESS language is a set of two or more primitive component called partial complex entity.

ENTITY person;
  name: STRING;
END_ENTITY;

ENTITY employee SUBTYPE OF (person);
  pay: INTEGER;
END_ENTITY;

ENTITY student SUBTYPE OF (person);
  school_name: STRING;
END_ENTITY;

In this EXPRESS schema, a complex entity of person can have three components representing person, employee, and student. There are two way of mapping it from an exchange structure. The internal mapping looks like usual case:

#1 = EMPLOYEE('Hitori Goto', 10);
#2 = STUDENT('Ikuno Kita', 'Shuka');

#1 has two parameters while employee definition has a field pay. These parameters are consumed by supertype person first, and then subtype employee consumes:

#1 = EMPLOYEE('Hitori Goto', 10);
              ▲              ▲
              │              └─ map to pay in employee
              └─ map to name in person

Internal mapping cannot handle the case where both employee and student components co-exist. This case will be handled by external mapping using SubSuperRecord.

The detail of internal mapping is defined in 12.2.5.2 “Internal mapping” of ISO-10303-21.

In terms of serde data model, Record is not self-describing when using internal mapping rule. Structs using internal mapping should implement serde::Deserialize as described in subtype-supertype constraint in EXPRESS schema.

Fields

name: Stringparameter: Parameter

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The error type that can be returned if some error occurs during deserialization. Read more

Require the Deserializer to figure out how to drive the visitor based on what data type is in the input. Read more

Hint that the Deserialize type is expecting a struct with a particular name and fields. Read more

Hint that the Deserialize type is expecting a bool value.

Hint that the Deserialize type is expecting an i8 value.

Hint that the Deserialize type is expecting an i16 value.

Hint that the Deserialize type is expecting an i32 value.

Hint that the Deserialize type is expecting an i64 value.

Hint that the Deserialize type is expecting an i128 value. Read more

Hint that the Deserialize type is expecting a u8 value.

Hint that the Deserialize type is expecting a u16 value.

Hint that the Deserialize type is expecting a u32 value.

Hint that the Deserialize type is expecting a u64 value.

Hint that the Deserialize type is expecting an u128 value. Read more

Hint that the Deserialize type is expecting a f32 value.

Hint that the Deserialize type is expecting a f64 value.

Hint that the Deserialize type is expecting a char value.

Hint that the Deserialize type is expecting a string value and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more

Hint that the Deserialize type is expecting a string value and would benefit from taking ownership of buffered data owned by the Deserializer. Read more

Hint that the Deserialize type is expecting a byte array and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more

Hint that the Deserialize type is expecting a byte array and would benefit from taking ownership of buffered data owned by the Deserializer. Read more

Hint that the Deserialize type is expecting an optional value. Read more

Hint that the Deserialize type is expecting a unit value.

Hint that the Deserialize type is expecting a unit struct with a particular name. Read more

Hint that the Deserialize type is expecting a newtype struct with a particular name. Read more

Hint that the Deserialize type is expecting a sequence of values.

Hint that the Deserialize type is expecting a sequence of values and knows how many values there are without looking at the serialized data. Read more

Hint that the Deserialize type is expecting a tuple struct with a particular name and number of fields. Read more

Hint that the Deserialize type is expecting a map of key-value pairs.

Hint that the Deserialize type is expecting an enum value with a particular name and possible variants. Read more

Hint that the Deserialize type is expecting the name of a struct field or the discriminant of an enum variant. Read more

Hint that the Deserialize type needs to deserialize a value whose type doesn’t matter because it is ignored. Read more

Determine whether Deserialize implementations should expect to deserialize their human-readable form. Read more

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.