Skip to content

Commit 73f8ad0

Browse files
committed
Add FromStr impl for Ordering
1 parent 41088db commit 73f8ad0

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

rust/src/model_ext.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! Extensions of the auto-generated "models" (schema structs).
22
3+
use std::str::FromStr;
4+
35
use serde_json::json;
46

5-
use crate::models::MessageIn;
7+
use crate::{api::Ordering, models::MessageIn};
68

79
impl MessageIn {
810
/// Create a new message with a pre-serialized payload.
@@ -38,3 +40,19 @@ impl MessageIn {
3840
self
3941
}
4042
}
43+
44+
#[derive(Debug, thiserror::Error)]
45+
#[error("invalid value for ordering")]
46+
pub struct OrderingFromStrError;
47+
48+
impl FromStr for Ordering {
49+
type Err = OrderingFromStrError;
50+
51+
fn from_str(s: &str) -> Result<Self, Self::Err> {
52+
match s {
53+
"ascending" => Ok(Self::Ascending),
54+
"descending" => Ok(Self::Descending),
55+
_ => Err(OrderingFromStrError),
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)