mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-05-10 07:28:05 +00:00
Serialize and deserialize CString through [u8]
This commit is contained in:
@@ -26,7 +26,7 @@ use std::net;
|
|||||||
use std::path;
|
use std::path;
|
||||||
use core::str;
|
use core::str;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::CString;
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@@ -55,6 +55,8 @@ use de::{Deserialize, Deserializer, EnumVisitor, Error, MapVisitor, SeqVisitor,
|
|||||||
VariantVisitor, Visitor};
|
VariantVisitor, Visitor};
|
||||||
use de::from_primitive::FromPrimitive;
|
use de::from_primitive::FromPrimitive;
|
||||||
|
|
||||||
|
use super::super::bytes::ByteBuf;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// A visitor that produces a `()`.
|
/// A visitor that produces a `()`.
|
||||||
@@ -302,7 +304,7 @@ impl Deserialize for CString {
|
|||||||
fn deserialize<D>(deserializer: D) -> Result<CString, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<CString, D::Error>
|
||||||
where D: Deserializer
|
where D: Deserializer
|
||||||
{
|
{
|
||||||
let v: Vec<u8> = try!(Deserialize::deserialize(deserializer));
|
let v: Vec<u8> = try!(ByteBuf::deserialize(deserializer)).into();
|
||||||
CString::new(v)
|
CString::new(v)
|
||||||
.map_err(|e| Error::custom(format!("unexpected NULL at byte {}", e.nul_position())))
|
.map_err(|e| Error::custom(format!("unexpected NULL at byte {}", e.nul_position())))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user