Skip to content

Commit

Permalink
Fix build fail with serde feature (#293)
Browse files Browse the repository at this point in the history
Verify no-std build and all features build
  • Loading branch information
taiki-e authored and Douman committed Sep 8, 2019
1 parent 97c1338 commit ebe9602
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
14 changes: 9 additions & 5 deletions ci/azure-test-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
displayName: cargo ${{ parameters.cmd }}

# Run with each specified feature
- ${{ each feature in parameters.features.value }}:
- ${{ each feature in parameters.features }}:
- script: cargo ${{ parameters.cmd }} --features ${{ feature }}
displayName: cargo ${{ parameters.cmd }} --tests --features ${{ feature }}
displayName: cargo ${{ parameters.cmd }} --features ${{ feature }}

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

# Run with no default defaults
- script: cargo ${{ parameters.cmd }}
displayName: cargo ${{ parameters.cmd }} --no-default-features
# Run with all features
- script: cargo ${{ parameters.cmd }} --all-features
displayName: cargo ${{ parameters.cmd }} --all-features

# Run with no default features
- script: cargo check --no-default-features
displayName: cargo check --no-default-features
12 changes: 7 additions & 5 deletions src/serde.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use alloc::string::String;
use alloc::vec::Vec;
use core::{cmp, fmt};
use serde::{Serialize, Serializer, Deserialize, Deserializer, de};
use super::{Bytes, BytesMut};

macro_rules! serde_impl {
($ty:ident, $visitor_ty:ident) => (
($ty:ident, $visitor_ty:ident, $from_slice:ident) => (
impl Serialize for $ty {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down Expand Up @@ -40,7 +42,7 @@ macro_rules! serde_impl {
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
where E: de::Error
{
Ok($ty::from(v))
Ok($ty::$from_slice(v))
}

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

#[inline]
Expand All @@ -76,5 +78,5 @@ macro_rules! serde_impl {
);
}

serde_impl!(Bytes, BytesVisitor);
serde_impl!(BytesMut, BytesMutVisitor);
serde_impl!(Bytes, BytesVisitor, copy_from_slice);
serde_impl!(BytesMut, BytesMutVisitor, from);

0 comments on commit ebe9602

Please sign in to comment.