Skip to content

Commit ebe9602

Browse files
taiki-eDouman
authored and
Douman
committed
Fix build fail with serde feature (#293)
Verify no-std build and all features build
1 parent 97c1338 commit ebe9602

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

ci/azure-test-stable.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ jobs:
2929
displayName: cargo ${{ parameters.cmd }}
3030

3131
# Run with each specified feature
32-
- ${{ each feature in parameters.features.value }}:
32+
- ${{ each feature in parameters.features }}:
3333
- script: cargo ${{ parameters.cmd }} --features ${{ feature }}
34-
displayName: cargo ${{ parameters.cmd }} --tests --features ${{ feature }}
34+
displayName: cargo ${{ parameters.cmd }} --features ${{ feature }}
3535

3636
- ${{ if eq(parameters.cmd, 'test') }}:
3737
- script: cargo doc --no-deps
@@ -41,6 +41,10 @@ jobs:
4141
- script: cargo check --benches
4242
displayName: Check benchmarks
4343

44-
# Run with no default defaults
45-
- script: cargo ${{ parameters.cmd }}
46-
displayName: cargo ${{ parameters.cmd }} --no-default-features
44+
# Run with all features
45+
- script: cargo ${{ parameters.cmd }} --all-features
46+
displayName: cargo ${{ parameters.cmd }} --all-features
47+
48+
# Run with no default features
49+
- script: cargo check --no-default-features
50+
displayName: cargo check --no-default-features

src/serde.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
use alloc::string::String;
2+
use alloc::vec::Vec;
13
use core::{cmp, fmt};
24
use serde::{Serialize, Serializer, Deserialize, Deserializer, de};
35
use super::{Bytes, BytesMut};
46

57
macro_rules! serde_impl {
6-
($ty:ident, $visitor_ty:ident) => (
8+
($ty:ident, $visitor_ty:ident, $from_slice:ident) => (
79
impl Serialize for $ty {
810
#[inline]
911
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -40,7 +42,7 @@ macro_rules! serde_impl {
4042
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
4143
where E: de::Error
4244
{
43-
Ok($ty::from(v))
45+
Ok($ty::$from_slice(v))
4446
}
4547

4648
#[inline]
@@ -54,7 +56,7 @@ macro_rules! serde_impl {
5456
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
5557
where E: de::Error
5658
{
57-
Ok($ty::from(v))
59+
Ok($ty::$from_slice(v.as_bytes()))
5860
}
5961

6062
#[inline]
@@ -76,5 +78,5 @@ macro_rules! serde_impl {
7678
);
7779
}
7880

79-
serde_impl!(Bytes, BytesVisitor);
80-
serde_impl!(BytesMut, BytesMutVisitor);
81+
serde_impl!(Bytes, BytesVisitor, copy_from_slice);
82+
serde_impl!(BytesMut, BytesMutVisitor, from);

0 commit comments

Comments
 (0)