mavlink_core/connection/direct_serial/
config.rs

1use core::fmt::Display;
2
3/// MAVLink address for a serial connection
4///
5/// # Example
6///
7/// ```ignore
8/// use mavlink::{Connectable, SerialConfig};
9///
10/// let config = SerialConfig::new("/dev/ttyTHS1".to_owned(), 115200);
11/// config.connect::<mavlink::ardupilotmega::MavMessage>();
12/// ```
13#[derive(Debug, Clone)]
14pub struct SerialConfig {
15    pub(crate) port_name: String,
16    pub(crate) baud_rate: u32,
17}
18
19impl SerialConfig {
20    /// Creates a serial connection address with port name and baud rate.
21    pub fn new(port_name: String, baud_rate: u32) -> Self {
22        Self {
23            port_name,
24            baud_rate,
25        }
26    }
27}
28
29impl Display for SerialConfig {
30    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
31        write!(f, "serial:{}:{}", self.port_name, self.baud_rate)
32    }
33}