Skip to content

Commit

Permalink
✨ Impl AsFixValue for bool
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurlm committed Jan 17, 2024
1 parent 234c5a1 commit 5579750
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions quickfix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ impl_as_fix_value!(isize);
impl_as_fix_value!(f32);
impl_as_fix_value!(f64);

impl AsFixValue for bool {
fn as_fix_value(&self) -> String {
// Check reference here: https://www.onixs.biz/fix-dictionary/4.3/tagNum_575.html
if *self { "Y" } else { "N" }.to_string()
}
}

/// Stores and organizes a collection of Fields.
///
/// This is the basis for a message, header, and trailer. This collection
Expand Down
12 changes: 8 additions & 4 deletions quickfix/tests/test_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ fn test_from_text() {
}

#[test]
fn test_set_field() {
fn test_set_field() -> Result<(), QuickFixError> {
let mut msg = Message::new();
msg.set_field(42, "foo").unwrap();
msg.set_field(56, "bar").unwrap();
msg.set_field(42, "foo")?;
msg.set_field(56, "bar")?;
msg.set_field(89, true)?;
msg.set_field(78, false)?;
msg.set_field(489, 1234)?;
assert_eq!(
msg.as_string().as_deref(),
Ok("9=14\u{1}42=foo\u{1}56=bar\u{1}10=162\u{1}")
Ok("9=33\u{1}42=foo\u{1}56=bar\u{1}78=N\u{1}89=Y\u{1}489=1234\u{1}10=083\u{1}")
);
Ok(())
}

#[test]
Expand Down

0 comments on commit 5579750

Please sign in to comment.