diff --git a/generator/sbpg/targets/resources/rust/sbp_messages_mod.rs b/generator/sbpg/targets/resources/rust/sbp_messages_mod.rs index af1721218..0c2f7e17d 100644 --- a/generator/sbpg/targets/resources/rust/sbp_messages_mod.rs +++ b/generator/sbpg/targets/resources/rust/sbp_messages_mod.rs @@ -79,7 +79,7 @@ mod lib { use lib::*; /// Common functionality available to all SBP messages. -pub trait SbpMessage { +pub trait SbpMessage: WireFormat + Clone { /// Get the message name. fn message_name(&self) -> &'static str; /// Get the message type. @@ -102,8 +102,7 @@ pub trait SbpMessage { /// Tells you if the message is valid or if it is not a valid message and may need to be /// special cased at certain points. fn is_valid(&self) -> bool; - fn into_valid_msg(self) -> Result - where Self: Sized; + fn into_valid_msg(self) -> Result; } /// Implemented by messages who's message name and type are known at compile time. diff --git a/rust/sbp/src/json/ser.rs b/rust/sbp/src/json/ser.rs index a4f6c830d..145061f4b 100644 --- a/rust/sbp/src/json/ser.rs +++ b/rust/sbp/src/json/ser.rs @@ -10,7 +10,6 @@ use super::{JsonError, JsonOutput}; use crate::{ json::{CommonJson, HaskellishFloatFormatter, Json2JsonInput, Json2JsonOutput}, messages::Sbp, - wire_format::WireFormat, SbpMessage, BUFLEN, CRC_LEN, HEADER_LEN, MIN_FRAME_LEN, PREAMBLE, }; @@ -20,7 +19,7 @@ const BASE64_BUFLEN: usize = BUFLEN * 4; pub fn to_writer(mut writer: W, msg: &M) -> Result<(), JsonError> where W: io::Write, - M: SbpMessage + Serialize + WireFormat + Clone, + M: SbpMessage + Serialize, { let mut frame = BytesMut::with_capacity(BUFLEN); let mut payload = String::with_capacity(BUFLEN); @@ -39,7 +38,7 @@ where /// Serialize the given message as a JSON byte vector. pub fn to_vec(msg: &M) -> Result, JsonError> where - M: SbpMessage + Serialize + WireFormat + Clone, + M: SbpMessage + Serialize, { let mut frame = BytesMut::with_capacity(BUFLEN); let mut payload = String::with_capacity(BUFLEN); @@ -63,7 +62,7 @@ pub fn to_buffer( ) -> Result<(), JsonError> where F: Formatter, - M: SbpMessage + Serialize + WireFormat + Clone, + M: SbpMessage + Serialize + Clone, { let output = JsonOutput { common: get_common_fields(payload_buf, frame_buf, msg)?, @@ -213,7 +212,7 @@ impl Encoder for Json2JsonEncoderInner } } -fn get_common_fields<'a, M: SbpMessage + WireFormat + Clone>( +fn get_common_fields<'a, M: SbpMessage>( payload_buf: &'a mut String, frame_buf: &'a mut BytesMut, msg: &M, diff --git a/rust/sbp/src/messages/mod.rs b/rust/sbp/src/messages/mod.rs index 69af4d597..dcaf43ed5 100644 --- a/rust/sbp/src/messages/mod.rs +++ b/rust/sbp/src/messages/mod.rs @@ -327,7 +327,7 @@ mod lib { use lib::*; /// Common functionality available to all SBP messages. -pub trait SbpMessage { +pub trait SbpMessage: WireFormat + Clone { /// Get the message name. fn message_name(&self) -> &'static str; /// Get the message type. @@ -350,9 +350,7 @@ pub trait SbpMessage { /// Tells you if the message is valid or if it is not a valid message and may need to be /// special cased at certain points. fn is_valid(&self) -> bool; - fn into_valid_msg(self) -> Result - where - Self: Sized; + fn into_valid_msg(self) -> Result; } /// Implemented by messages who's message name and type are known at compile time. diff --git a/rust/sbp/src/ser.rs b/rust/sbp/src/ser.rs index 8aeedd386..0665fe630 100644 --- a/rust/sbp/src/ser.rs +++ b/rust/sbp/src/ser.rs @@ -34,7 +34,7 @@ use crate::{BUFLEN, MAX_PAYLOAD_LEN, PREAMBLE}; pub fn to_writer(mut writer: W, msg: &M) -> Result<(), Error> where W: io::Write, - M: SbpMessage + WireFormat, + M: SbpMessage, { let mut buf = BytesMut::with_capacity(BUFLEN); to_buffer(&mut buf, msg)?; @@ -64,16 +64,13 @@ where /// Ok(()) /// } /// ``` -pub fn to_vec(msg: &M) -> Result, Error> { +pub fn to_vec(msg: &M) -> Result, Error> { let mut buf = BytesMut::with_capacity(BUFLEN); to_buffer(&mut buf, msg)?; Ok(buf.to_vec()) } -pub fn to_buffer( - buf: &mut BytesMut, - msg: &M, -) -> Result<(), WriteFrameError> { +pub fn to_buffer(buf: &mut BytesMut, msg: &M) -> Result<(), WriteFrameError> { if !msg.is_valid() { msg.write(buf); return Ok(());