Skip to content

Commit

Permalink
🏷️ Update argument type of FieldMap::set_field
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurlm committed Jan 12, 2024
1 parent 3e182c5 commit 5e9a53a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions quickfix/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl FieldMap for Group {
unsafe { FixGroup_getField(self.0, tag) }.map(read_checked_cstr)
}

fn set_field(&mut self, tag: i32, value: &str) -> Result<(), QuickFixError> {
let ffi_value = CString::new(value)?;
fn set_field<V: AsRef<str>>(&mut self, tag: i32, value: V) -> Result<(), QuickFixError> {
let ffi_value = CString::new(value.as_ref())?;
ffi_code_to_result(unsafe { FixGroup_setField(self.0, tag, ffi_value.as_ptr()) })
}

Expand Down
4 changes: 2 additions & 2 deletions quickfix/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ impl FieldMap for Header {
unsafe { FixHeader_getField(self.0, tag) }.map(read_checked_cstr)
}

fn set_field(&mut self, tag: i32, value: &str) -> Result<(), QuickFixError> {
let ffi_value = CString::new(value)?;
fn set_field<V: AsRef<str>>(&mut self, tag: i32, value: V) -> Result<(), QuickFixError> {
let ffi_value = CString::new(value.as_ref())?;
ffi_code_to_result(unsafe { FixHeader_setField(self.0, tag, ffi_value.as_ptr()) })
}

Expand Down
2 changes: 1 addition & 1 deletion quickfix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub trait FieldMap {
fn get_field(&self, tag: i32) -> Option<String>;

/// Set field value for a given tag number.
fn set_field(&mut self, tag: i32, value: &str) -> Result<(), QuickFixError>;
fn set_field<V: AsRef<str>>(&mut self, tag: i32, value: V) -> Result<(), QuickFixError>;

/// Remove a field from collection.
fn remove_field(&mut self, tag: i32) -> Result<(), QuickFixError>;
Expand Down
4 changes: 2 additions & 2 deletions quickfix/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ impl FieldMap for Message {
unsafe { FixMessage_getField(self.0, tag) }.map(read_checked_cstr)
}

fn set_field(&mut self, tag: i32, value: &str) -> Result<(), QuickFixError> {
let ffi_value = CString::new(value)?;
fn set_field<V: AsRef<str>>(&mut self, tag: i32, value: V) -> Result<(), QuickFixError> {
let ffi_value = CString::new(value.as_ref())?;
ffi_code_to_result(unsafe { FixMessage_setField(self.0, tag, ffi_value.as_ptr()) })
}

Expand Down
4 changes: 2 additions & 2 deletions quickfix/src/trailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ impl FieldMap for Trailer {
unsafe { FixTrailer_getField(self.0, tag) }.map(read_checked_cstr)
}

fn set_field(&mut self, tag: i32, value: &str) -> Result<(), QuickFixError> {
let ffi_value = CString::new(value)?;
fn set_field<V: AsRef<str>>(&mut self, tag: i32, value: V) -> Result<(), QuickFixError> {
let ffi_value = CString::new(value.as_ref())?;
ffi_code_to_result(unsafe { FixTrailer_setField(self.0, tag, ffi_value.as_ptr()) })
}

Expand Down
4 changes: 2 additions & 2 deletions quickfix/tests/utils/msg_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ pub fn build_news(headline: &str, lines: &[&str]) -> Result<Message, QuickFixErr
msg.with_header_mut(|h| h.set_field(MSG_TYPE, "B"))?;

msg.set_field(MSG_HEADLINE, headline)?;
msg.set_field(MSG_NO_LINES_OF_TEXT, &lines.len().to_string())?; // Not required but always nice
msg.set_field(MSG_NO_LINES_OF_TEXT, lines.len().to_string())?; // Not required but always nice

for line in lines {
let mut group = Group::try_new(MSG_NO_LINES_OF_TEXT, MSG_TEXT)?;
group.set_field(MSG_TEXT, &line)?;
group.set_field(MSG_TEXT, line)?;
msg.add_group(&group)?;
}

Expand Down

0 comments on commit 5e9a53a

Please sign in to comment.