diff --git a/quickfix/src/lib.rs b/quickfix/src/lib.rs index a4ef909..ae2a027 100644 --- a/quickfix/src/lib.rs +++ b/quickfix/src/lib.rs @@ -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 diff --git a/quickfix/tests/test_messages.rs b/quickfix/tests/test_messages.rs index 07d7c39..afde005 100644 --- a/quickfix/tests/test_messages.rs +++ b/quickfix/tests/test_messages.rs @@ -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]