From ebe96021b0eaf52be1fedd0a925f4384275c9cc4 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 9 Sep 2019 05:10:46 +0900 Subject: [PATCH] Fix build fail with serde feature (#293) Verify no-std build and all features build --- ci/azure-test-stable.yml | 14 +++++++++----- src/serde.rs | 12 +++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ci/azure-test-stable.yml b/ci/azure-test-stable.yml index b402696a3..e543eeeb4 100644 --- a/ci/azure-test-stable.yml +++ b/ci/azure-test-stable.yml @@ -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 @@ -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 diff --git a/src/serde.rs b/src/serde.rs index 8f6b902ea..6ad0331f8 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -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(&self, serializer: S) -> Result @@ -40,7 +42,7 @@ macro_rules! serde_impl { fn visit_bytes(self, v: &[u8]) -> Result where E: de::Error { - Ok($ty::from(v)) + Ok($ty::$from_slice(v)) } #[inline] @@ -54,7 +56,7 @@ macro_rules! serde_impl { fn visit_str(self, v: &str) -> Result where E: de::Error { - Ok($ty::from(v)) + Ok($ty::$from_slice(v.as_bytes())) } #[inline] @@ -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);