Enum ruststep::ast::Parameter[][src]

pub enum Parameter {
    Typed {
        keyword: String,
        parameter: Box<Parameter>,
    },
    Integer(i64),
    Real(f64),
    String(String),
    Enumeration(String),
    List(Vec<Parameter>),
    Ref(Name),
    NotProvided,
    Omitted,
}
Expand description

Primitive value type in STEP data

Inline struct or list can be nested, i.e. Parameter can be a tree.

use nom::Finish;
use ruststep::{parser::exchange, ast::{Parameter, Record}};

let (residual, p) = exchange::parameter("B((1.0, A((2.0, 3.0))))")
    .finish()
    .unwrap();
assert_eq!(residual, "");

// A((2.0, 3.0))
let a = Parameter::Typed {
    keyword: "A".to_string(),
    parameter: Box::new(vec![Parameter::real(2.0), Parameter::real(3.0)].into()),
};

// B((1.0, a))
let b = Parameter::Typed {
    keyword: "B".to_string(),
    parameter: Box::new(vec![Parameter::real(1.0), a].into()),
};

assert_eq!(p, b);

FromIterator

Create a list as Parameter::List from Iterator<Item=Parameter> or Iterator<Item=&Parameter>.

use ruststep::ast::Parameter;

let p: Parameter = [Parameter::real(1.0), Parameter::real(2.0)]
    .iter()
    .collect();
assert!(matches!(p, Parameter::List(_)));

Deserialize

Parameterserde data model
Integeri64
Realf64
Stringstring
Listseq
NotProvidedoption (always none)
Omittedoption (always none)
Enumerationunit_variant (through serde::de::value::StringDeserializer)
Typedmap (through de::RecordDeserializer)
Refnewtype_variant

Variants

Typed

Corresponding to TYPED_PARAMETER in WSN:

TYPED_PARAMETER = KEYWORD "(" PARAMETER ")" .

and parser::exchange::typed_parameter. It takes only one PARAMETER different from Record, which takes many PARAMETERs.

SIMPLE_RECORD = KEYWORD "(" [ PARAMETER_LIST ] ")" .

FromStr

use std::str::FromStr;
use ruststep::ast::Parameter;

let p = Parameter::from_str("FILE_NAME('ruststep')").unwrap();
assert!(matches!(p, Parameter::Typed { .. }));

Deserialize

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

// Regarded as a map `{ "A": [1, 2] }` in serde data model
let p = Parameter::from_str("A((1, 2))").unwrap();

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

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

Different from Record, deserializing into a struct is not supported:

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

let p = Parameter::from_str("A(1)").unwrap();

#[derive(Debug, Clone, PartialEq, Deserialize)]
struct A {
    x: i32,
}
assert!(A::deserialize(&p).is_err());

Fields of Typed

keyword: Stringparameter: Box<Parameter>
Integer(i64)

Signed integer

FromStr

use std::str::FromStr;
use ruststep::ast::Parameter;

let p = Parameter::from_str("10").unwrap();
assert_eq!(p, Parameter::Integer(10));

let p = Parameter::from_str("-10").unwrap();
assert_eq!(p, Parameter::Integer(-10));

Deserialize

use ruststep::ast::*;
use serde::Deserialize;

let p = Parameter::Integer(2);
let a = i64::deserialize(&p).unwrap();
assert_eq!(a, 2);

// can be deserialized as unsigned
let a = u64::deserialize(&p).unwrap();
assert_eq!(a, 2);

// cannot be deserialized negative integer into unsigned
let p = Parameter::Integer(-2);
let a = i64::deserialize(&p).unwrap();
assert_eq!(a, -2);
assert!(u64::deserialize(&p).is_err());

Tuple Fields of Integer

0: i64
Real(f64)

Real number

FromStr

use std::str::FromStr;
use ruststep::ast::Parameter;

let p = Parameter::from_str("1.0").unwrap();
assert_eq!(p, Parameter::Real(1.0));

Tuple Fields of Real

0: f64
String(String)

string literal

FromStr

use std::str::FromStr;
use ruststep::ast::Parameter;

let p = Parameter::from_str("'EXAMPLE STRING'").unwrap();
assert_eq!(p, Parameter::String("EXAMPLE STRING".to_string()));

Tuple Fields of String

0: String
Enumeration(String)

Enumeration defined in EXPRESS schema, like .TRUE.

FromStr

let p = Parameter::from_str(".TRUE.").unwrap();
assert_eq!(p, Parameter::Enumeration("TRUE".to_string()));

Deserialize

use ruststep::ast::*;
use serde::Deserialize;
use std::str::FromStr;

let p = Parameter::from_str(".A.").unwrap();

#[derive(Debug, PartialEq, Deserialize)]
enum E {
  A,
  B
}
assert_eq!(E::deserialize(&p).unwrap(), E::A);

Tuple Fields of Enumeration

0: String
List(Vec<Parameter>)

List of parameters. This can be non-uniform.

FromStr

use std::str::FromStr;
use ruststep::ast::Parameter;

let p = Parameter::from_str("(1.0, 2, 'STRING')").unwrap();
assert_eq!(p, Parameter::List(vec![
  Parameter::Real(1.0),
  Parameter::Integer(2),
  Parameter::String("STRING".to_string()),
]));

Deserialize

use std::str::FromStr;
use ruststep::ast::*;
use serde::Deserialize;

let p = Parameter::from_str("(1, 2, 3)").unwrap();

// As Vec<i32>
let a = Vec::<i32>::deserialize(&p).unwrap();
assert_eq!(a, vec![1, 2, 3]);

// As user-defined struct
#[derive(Debug, Clone, PartialEq, Deserialize)]
struct A {
    x: i32,
    y: i32,
    z: i32,
}
let a = A::deserialize(&p).unwrap();
assert_eq!(a, A { x: 1, y: 2, z: 3 });

Tuple Fields of List

0: Vec<Parameter>
Ref(Name)

A reference to entity or value

Deserialize

use ruststep::ast::*;
use serde::Deserialize;
use std::str::FromStr;

let p = Parameter::from_str("#12").unwrap();

#[derive(Debug, PartialEq, Deserialize)]
enum Id {
  #[serde(rename = "Entity")] // "Entity" is keyword for entity reference
  E(usize),
  #[serde(rename = "Value")]  // "Value" is keyword for value reference
  V(usize),
}
assert_eq!(Id::deserialize(&p).unwrap(), Id::E(12));

Tuple Fields of Ref

0: Name
NotProvided

The special token dollar sign ($) is used to represent an object whose value is not provided in the exchange structure.

Deserialize

use ruststep::ast::*;
use serde::Deserialize;

let p = Parameter::NotProvided;
assert_eq!(Option::<i64>::deserialize(&p).unwrap(), None);
Omitted

Omitted parameter denoted by *

Deserialize

use ruststep::ast::*;
use serde::Deserialize;

let p = Parameter::Omitted;
assert_eq!(Option::<i64>::deserialize(&p).unwrap(), None);

Implementations

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 bool value.

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

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 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 struct with a particular name and fields. 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

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

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.