#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CommandFailure {
NotSent(String),
Ambiguous(String),
VenueRejected(String),
}
impl CommandFailure {
#[must_use]
pub fn not_sent(reason: impl Into<String>) -> Self {
Self::NotSent(reason.into())
}
#[must_use]
pub fn ambiguous(reason: impl Into<String>) -> Self {
Self::Ambiguous(reason.into())
}
#[must_use]
pub fn venue_rejected(reason: impl Into<String>) -> Self {
Self::VenueRejected(reason.into())
}
}
#[cfg(test)]
mod tests {
use rstest::rstest;
use super::CommandFailure;
#[rstest]
#[case(
CommandFailure::not_sent("Failed to build cancel params"),
CommandFailure::NotSent("Failed to build cancel params".to_string())
)]
#[case(
CommandFailure::ambiguous("connection closed"),
CommandFailure::Ambiguous("connection closed".to_string())
)]
#[case(
CommandFailure::venue_rejected("EOrder:Unknown order"),
CommandFailure::VenueRejected("EOrder:Unknown order".to_string())
)]
fn test_constructor_variant_and_reason(
#[case] failure: CommandFailure,
#[case] expected: CommandFailure,
) {
assert_eq!(failure, expected);
}
}