#[non_exhaustive]pub struct Characteristic {
pub id: Option<String>,
pub name: Option<String>,
pub value_type: Option<String>,
pub value: Option<Value>,
pub characteristic_relationship: Option<Vec<CharacteristicRelationship>>,
pub at_type: String,
pub at_base_type: Option<String>,
pub at_schema_location: Option<String>,
pub extensions: Extensions,
}Expand description
A name/value pair describing one attribute of an entity.
The v5 OAS gives each value shape its own subclass —
StringCharacteristic, IntegerArrayCharacteristic, twelve in all. This
is one struct instead: the shared members stay typed, value holds any
JSON, and @type names the subclass, so a vendor subclass never fails to
parse and value_kind reads the class back.
§Build with new
The subclass follows from the value, so new derives it. The builder
cannot — it sets @type before it has seen the value — so use it only
for members new does not set, and follow it with with_value.
use rutmf::core::{Characteristic, ValueKind};
let speed = Characteristic::new("downstreamSpeed", 100);
assert_eq!(speed.type_name(), "IntegerCharacteristic");
assert_eq!(speed.value_kind(), ValueKind::Integer);
let bare = Characteristic::builder().name("downstreamSpeed").value(100).build();
assert_eq!(bare.type_name(), "Characteristic", "the builder cannot know");valueType is not derived: it looks like a JSON type name and is not
one. The corpus uses it for Quantity and Slice5G JSON descriptor as
readily as for string, so it is a domain label only the caller knows.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: Option<String>Unique identifier of the characteristic.
name: Option<String>Name of the characteristic.
value_type: Option<String>Data type of the value, e.g. string, integer.
value: Option<Value>The value itself, shaped according to @type.
characteristic_relationship: Option<Vec<CharacteristicRelationship>>Relationships to other characteristics.
at_type: StringThe @type discriminator naming this entity’s class.
Empty when the payload declared none — TMF630 v5 marks it
required, but servers omit it and so do TM Forum’s own examples.
An absent discriminator stays absent, so relaying a payload does
not silently add a member to it; anything this crate builds
carries the class name. Read it through
type_name, which resolves the empty case.
at_base_type: Option<String>The @baseType, naming the supertype where this class is sub-typed.
at_schema_location: Option<String>A URI to a JSON-Schema file defining additional attributes.
extensions: ExtensionsMembers not covered by the typed model, kept in document order.
See the crate documentation for the round-trip guarantee this underwrites.
Implementations§
Source§impl Characteristic
impl Characteristic
Sourcepub fn builder() -> CharacteristicBuilder
pub fn builder() -> CharacteristicBuilder
Create an instance of Characteristic using the builder syntax
Source§impl Characteristic
impl Characteristic
Sourcepub fn new(name: impl Into<String>, value: impl Into<Value>) -> Self
pub fn new(name: impl Into<String>, value: impl Into<Value>) -> Self
A named characteristic whose class follows from the value.
use rutmf::core::Characteristic;
assert_eq!(Characteristic::new("tier", "gold").type_name(), "StringCharacteristic");
assert_eq!(Characteristic::new("enabled", true).type_name(), "BooleanCharacteristic");
assert_eq!(
Characteristic::new("bands", vec!["n78", "n1"]).type_name(),
"StringArrayCharacteristic",
);A value whose shape names no subclass — null, an empty array, an array
of mixed types — leaves the base class rather than guessing at one.
Sourcepub fn with_value(self, value: impl Into<Value>) -> Self
pub fn with_value(self, value: impl Into<Value>) -> Self
Sets the value, and the @type that value implies.
The class stays as it was when the value names no subclass, so this never replaces a subclass a server sent with the bare base.
Sourcepub fn with_value_type(self, value_type: impl Into<String>) -> Self
pub fn with_value_type(self, value_type: impl Into<String>) -> Self
Sets the valueType label.
Free text — what the value means, not what shape it has, which is
value_kind’s question.
Sourcepub fn value_kind(&self) -> ValueKind
pub fn value_kind(&self) -> ValueKind
The value shape this characteristic’s @type declares.
Reads the subclass, so it reports what the sender said. Compare with
ValueKind::of_value, which reports what the value is, to catch a
payload where the two disagree.
use rutmf::core::{Characteristic, ValueKind};
let odd: Characteristic =
serde_json::from_str(r#"{"@type":"IntegerCharacteristic","value":"12"}"#).unwrap();
assert_eq!(odd.value_kind(), ValueKind::Integer);
assert_eq!(
odd.value.as_ref().map(ValueKind::of_value),
Some(ValueKind::String),
);Trait Implementations§
Source§impl Clone for Characteristic
impl Clone for Characteristic
Source§impl Debug for Characteristic
impl Debug for Characteristic
Source§impl Default for Characteristic
impl Default for Characteristic
Source§impl<'de> Deserialize<'de> for Characteristic
impl<'de> Deserialize<'de> for Characteristic
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for Characteristic
Available on crate feature schemars only.
impl JsonSchema for Characteristic
schemars only.Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more