11 stable releases

1.4.1 Sep 1, 2022
1.4.0 Mar 11, 2022
1.3.0 Feb 23, 2022
1.1.3 Jan 5, 2022
1.0.1 Oct 19, 2021

#792 in Encoding

Download history 78/week @ 2024-07-26 18/week @ 2024-08-02 21/week @ 2024-08-09 13/week @ 2024-08-16 12/week @ 2024-08-23 19/week @ 2024-08-30 13/week @ 2024-09-06 26/week @ 2024-09-13 58/week @ 2024-09-20 39/week @ 2024-09-27 251/week @ 2024-10-04 763/week @ 2024-10-11 424/week @ 2024-10-18 170/week @ 2024-10-25 534/week @ 2024-11-01 386/week @ 2024-11-08

1,651 downloads per month
Used in 4 crates

MIT license

71KB
1.5K SLoC

Namespace aware XML (de)serializer for Rust utilizing Serde

// XML elements can be specified with structs
#[derive(Debug, Serialize, Deserialize)]
pub struct BulkObservable {
    // Required attributes can easily be defined, with the format of {namespace}ns-prefix:element
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}iodef:BulkObservableList")]
    pub list: String,

    // Repeated and optional elements can be defined with Vec and Option
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}iodef:AdditionalData", default, skip_serializing_if="Vec::is_empty")]
    pub additional_data: Vec<ExtensionType>,
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}iodef:BulkObservableFormat", default, skip_serializing_if="Option::is_none")]
    pub format: Option<BulkObservableFormat>,

    // Element attributes can be specified with the $attr: prefix
    #[serde(rename = "$attr:type")]
    pub bulk_type: BulkObservableType,
    #[serde(rename = "$attr:ext-type", default, skip_serializing_if="Option::is_none")]
    pub bulk_ext_type: Option<String>,

    // Textual element content can be set with the special name $value
    #[serde(rename = "$value")]
    pub value: f64,
}

// Enumerated values can also be defined
#[derive(Debug, Serialize, Deserialize)]
pub enum ConfidenceRating {
    #[serde(rename = "low")]
    Low,
    #[serde(rename = "medium")]
    Medium,
    #[serde(rename = "high")]
    High,
    #[serde(rename = "numeric")]
    Numeric,
    #[serde(rename = "unknown")]
    Unknown
}

// As can enumerated objects
#[derive(Debug, Serialize, Deserialize)]
pub enum IndicatorExpressionInner {
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}IndicatorExpression")]
    IndicatorExpression(IndicatorExpression),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}Observable")]
    Observable(Observable),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}ObservableReference")]
    ObservableReference(ObservableReference),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}IndicatorReference")]
    IndicatorReference(IndicatorReference),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}AdditionalData")]
    AdditionalData(ExtensionType),
}

Dependencies

~4–13MB
~136K SLoC