Skip to content

Commit

Permalink
Add FromStr impl for Ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Dec 11, 2024
1 parent 41088db commit 73f8ad0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion rust/src/model_ext.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<Self, Self::Err> {
match s {
"ascending" => Ok(Self::Ascending),
"descending" => Ok(Self::Descending),
_ => Err(OrderingFromStrError),
}
}
}

0 comments on commit 73f8ad0

Please sign in to comment.