Skip to main content

fixer_fix/fix40/
logout.rs

1// Code generated by fixer-gen. DO NOT EDIT.
2#![allow(clippy::new_without_default)]
3#![allow(clippy::needless_pass_by_value)]
4#![allow(clippy::too_many_arguments)]
5#![allow(unused_imports)]
6
7use fixer::message::Message;
8use fixer::fix_string::FIXString;
9use fixer::errors::MessageRejectErrorEnum;
10use fixer::session::session_id::SessionID;
11
12
13use crate::field;
14use crate::tag;
15
16/// `Logout` is the `fix40` `Logout` type, `MsgType` = 5.
17pub struct Logout {
18    pub message: Message,
19}
20
21impl Logout {
22    /// Creates a new `Logout` with required fields.
23    pub fn new() -> Self {
24        let mut msg = Message::new();
25        msg.header.set_field(tag::MSG_TYPE, FIXString::from("5".to_string()));
26
27        Self { message: msg }
28    }
29
30    /// Creates a `Logout` from an existing `Message`.
31    pub fn from_message(msg: Message) -> Self {
32        Self { message: msg }
33    }
34
35    /// Returns the underlying `Message`.
36    pub fn to_message(self) -> Message {
37        self.message
38    }
39
40
41
42
43    /// Sets `Text`, Tag 58.
44    pub fn set_text(&mut self, v: String) {
45        self.message.body.set_field(tag::TEXT, FIXString::from(v));
46    }
47
48    /// Gets `Text`, Tag 58.
49    pub fn get_text(&self) -> Result<String, MessageRejectErrorEnum> {
50        let mut fld = field::TextField::new(String::new());
51        self.message.body.get_field(tag::TEXT, &mut fld.0)?;
52        Ok(fld.value().to_string())
53    }
54
55
56    /// Returns true if `Text` is present, Tag 58.
57    pub fn has_text(&self) -> bool {
58        self.message.body.has(tag::TEXT)
59    }
60
61
62}
63
64/// `RouteOut` is the callback type for routing `Logout` messages.
65pub type RouteOut = fn(msg: Logout, session_id: SessionID) -> Result<(), MessageRejectErrorEnum>;
66
67/// Route type returned by the `route` function.
68pub type Route = (&'static str, &'static str, Box<dyn Fn(&Message, SessionID) -> Result<(), MessageRejectErrorEnum> + Send>);
69
70/// Returns the begin string, message type, and route function for `Logout`.
71pub fn route(router: RouteOut) -> Route {
72    let r = move |msg: &Message, session_id: SessionID| -> Result<(), MessageRejectErrorEnum> {
73        router(Logout::from_message(msg.clone()), session_id)
74    };
75    ("FIX.4.0", "5", Box::new(r))
76}