mirror of
https://github.com/openharmony/third_party_rust_bytes.git
synced 2026-07-18 16:24:29 -04:00
Fix build fail with serde feature (#293)
Verify no-std build and all features build
This commit is contained in:
@@ -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
|
||||
|
||||
+7
-5
@@ -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>
|
||||
@@ -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]
|
||||
@@ -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]
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user