Skip to content

Commit 7360db8

Browse files
author
Jason Mobarak
authored
rust: fix serde feature for standalone compilation (#1191)
* rust: fix serde feature for standalone compilation * fix float_roundtrip compile
1 parent 06b3539 commit 7360db8

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

generator/sbpg/targets/resources/rust/sbp_cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ default = []
2222
async = ["futures", "dencode/async"]
2323
serde = ["dep:serde", "serde-big-array"]
2424
json = ["serde", "serde_json", "base64"]
25-
float_roundtrip = ["serde_json/float_roundtrip"]
25+
float_roundtrip = ["serde", "serde_json/float_roundtrip"]
2626
link = ["slotmap"]
2727

2828
[lib]

generator/sbpg/targets/resources/rust/sbp_messages_mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub enum Sbp {
123123
Unknown( Unknown ),
124124
}
125125

126-
#[cfg(feature = "serde")]
126+
#[cfg(feature = "serde_json")]
127127
impl<'de> serde::Deserialize<'de> for Sbp {
128128
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
129129
where

rust/sbp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ default = []
2222
async = ["futures", "dencode/async"]
2323
serde = ["dep:serde", "serde-big-array"]
2424
json = ["serde", "serde_json", "base64"]
25-
float_roundtrip = ["serde_json/float_roundtrip"]
25+
float_roundtrip = ["serde", "serde_json/float_roundtrip"]
2626
link = ["slotmap"]
2727

2828
[lib]

rust/sbp/src/messages/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ pub enum Sbp {
795795
Unknown(Unknown),
796796
}
797797

798-
#[cfg(feature = "serde")]
798+
#[cfg(feature = "serde_json")]
799799
impl<'de> serde::Deserialize<'de> for Sbp {
800800
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
801801
where

rust/sbp/src/sbp_string.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use std::convert::TryInto;
21
use std::fmt;
3-
use std::fmt::Formatter;
42
use std::marker::PhantomData;
53

64
use bytes::{Buf, BufMut};
5+
#[cfg(feature = "serde")]
76
use serde::de::{Error, Visitor};
87

98
use crate::wire_format::WireFormat;
@@ -84,7 +83,7 @@ impl<'de, E> serde::Deserialize<'de> for SbpString<Vec<u8>, E> {
8483
impl<'de, E> Visitor<'de> for SbpStringVisitor<E> {
8584
type Value = SbpString<Vec<u8>, E>;
8685

87-
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
86+
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
8887
formatter.write_str("string")
8988
}
9089

@@ -126,12 +125,14 @@ impl<'de, E, const LEN: usize> serde::Deserialize<'de> for SbpString<[u8; LEN],
126125
where
127126
D: serde::Deserializer<'de>,
128127
{
128+
use std::convert::TryInto;
129+
129130
struct SbpStringVisitor<E, const LEN: usize>(PhantomData<SbpString<[u8; LEN], E>>);
130131

131132
impl<'de, E, const LEN: usize> Visitor<'de> for SbpStringVisitor<E, LEN> {
132133
type Value = SbpString<[u8; LEN], E>;
133134

134-
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
135+
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
135136
formatter.write_str("string")
136137
}
137138

scripts/ci_build_rust.bash

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ else
2424
exit 1
2525
fi
2626

27+
cargo build --no-default-features -p sbp
28+
cargo build --no-default-features -p sbp --features serde
29+
cargo build --no-default-features -p sbp --features json
30+
cargo build --no-default-features -p sbp --features async
31+
cargo build --no-default-features -p sbp --features link
32+
cargo build --no-default-features -p sbp --features float_roundtrip
33+
2734
if [ "$RUNNER_OS" == "Linux" ]; then
2835
cargo build --all --release --target=x86_64-unknown-linux-musl
2936
cd target/x86_64-unknown-linux-musl/release

0 commit comments

Comments
 (0)