Skip to main content

Parameter

Enum Parameter 

Source
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 step_p21::{
    ast::{Parameter, Record},
    parser::exchange,
};

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 step_p21::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 step_p21::ast::Parameter;

let p = Parameter::from_str("FILE_NAME('step_p21')").unwrap();
assert!(matches!(p, Parameter::Typed { .. }));
§Deserialize
use serde::Deserialize;
use std::{collections::HashMap, str::FromStr};
use step_p21::ast::*;

// 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 serde::Deserialize;
use std::{collections::HashMap, str::FromStr};
use step_p21::ast::*;

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

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

Fields

§keyword: String
§parameter: Box<Parameter>
§

Integer(i64)

Signed integer

§FromStr
use std::str::FromStr;
use step_p21::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 serde::Deserialize;
use step_p21::ast::*;

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());
§

Real(f64)

Real number

§FromStr
use std::str::FromStr;
use step_p21::ast::Parameter;

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

String(String)

string literal

§FromStr
use std::str::FromStr;
use step_p21::ast::Parameter;

let p = Parameter::from_str("'EXAMPLE STRING'").unwrap();
assert_eq!(p, Parameter::String("EXAMPLE STRING".to_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 serde::Deserialize;
use std::str::FromStr;
use step_p21::ast::*;

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

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

List(Vec<Parameter>)

List of parameters. This can be non-uniform.

§FromStr
use std::str::FromStr;
use step_p21::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 serde::Deserialize;
use std::str::FromStr;
use step_p21::ast::*;

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 });
§

Ref(Name)

A reference to entity or value

§Deserialize
use serde::Deserialize;
use std::str::FromStr;
use step_p21::ast::*;

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));
§

NotProvided

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

§Deserialize
use serde::Deserialize;
use step_p21::ast::*;

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

Omitted

Omitted parameter denoted by *

§Deserialize
use serde::Deserialize;
use step_p21::ast::*;

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

Implementations§

Source§

impl Parameter

Source

pub fn integer(i: i64) -> Self

Source

pub fn real(x: f64) -> Self

Source

pub fn string(s: &str) -> Self

Trait Implementations§

Source§

impl AST for Parameter

Source§

fn parse(input: &str) -> ParseResult<'_, Self>

Source§

impl Clone for Parameter

Source§

fn clone(&self) -> Parameter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Parameter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserializer<'de> for &Parameter

Source§

type Error = Error

The error type that can be returned if some error occurs during deserialization.
Source§

fn deserialize_i8<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_i128<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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

fn deserialize_u8<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_u128<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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

fn deserialize_f32<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_char<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a char value.
Source§

fn deserialize_str<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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
Source§

fn deserialize_string<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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
Source§

fn deserialize_bytes<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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
Source§

fn deserialize_byte_buf<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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
Source§

fn deserialize_unit<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_unit_struct<V>( self, name: &'static str, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit struct with a particular name.
Source§

fn deserialize_newtype_struct<V>( self, name: &'static str, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a newtype struct with a particular name.
Source§

fn deserialize_seq<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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

fn deserialize_tuple<V>( self, len: usize, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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

fn deserialize_struct<V>( self, name: &'static str, fields: &'static [&'static str], visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a struct with a particular name and fields.
Source§

fn deserialize_tuple_struct<V>( self, name: &'static str, len: usize, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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

fn deserialize_map<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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

fn deserialize_enum<V>( self, name: &'static str, variants: &'static [&'static str], visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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

fn deserialize_identifier<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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

fn deserialize_ignored_any<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

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

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

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

fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

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

fn is_human_readable(&self) -> bool

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

impl From<Name> for Parameter

Source§

fn from(value: Name) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Parameter

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Parameter>> for Parameter

Source§

fn from(value: Vec<Parameter>) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Parameter

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Parameter

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl<'a> FromIterator<&'a Parameter> for Parameter

Source§

fn from_iter<Iter: IntoIterator<Item = &'a Parameter>>(iter: Iter) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Parameter> for Parameter

Source§

fn from_iter<Iter: IntoIterator<Item = Parameter>>(iter: Iter) -> Self

Creates a value from an iterator. Read more
Source§

impl FromStr for Parameter

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(input: &str) -> Result<Self>

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

impl PartialEq for Parameter

Source§

fn eq(&self, other: &Parameter) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Parameter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.