From 55797504fd99d046594b0d783e8d40ab9439d1b7 Mon Sep 17 00:00:00 2001 From: Arthur LE MOIGNE Date: Wed, 17 Jan 2024 16:10:36 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Impl=20AsFixValue=20for=20bool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quickfix/src/lib.rs | 7 +++++++ quickfix/tests/test_messages.rs | 12 ++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) 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]