diff --git a/rust/src/model_ext.rs b/rust/src/model_ext.rs index 632bfc76c..7c258f4c5 100644 --- a/rust/src/model_ext.rs +++ b/rust/src/model_ext.rs @@ -1,8 +1,10 @@ //! Extensions of the auto-generated "models" (schema structs). +use std::str::FromStr; + use serde_json::json; -use crate::models::MessageIn; +use crate::{api::Ordering, models::MessageIn}; impl MessageIn { /// Create a new message with a pre-serialized payload. @@ -38,3 +40,19 @@ impl MessageIn { self } } + +#[derive(Debug, thiserror::Error)] +#[error("invalid value for ordering")] +pub struct OrderingFromStrError; + +impl FromStr for Ordering { + type Err = OrderingFromStrError; + + fn from_str(s: &str) -> Result { + match s { + "ascending" => Ok(Self::Ascending), + "descending" => Ok(Self::Descending), + _ => Err(OrderingFromStrError), + } + } +}