mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-07-10 21:47:21 +00:00
Use the existing CString error message
This commit is contained in:
@@ -305,9 +305,8 @@ 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!(ByteBuf::deserialize(deserializer)).into();
|
let bytes = try!(ByteBuf::deserialize(deserializer));
|
||||||
CString::new(v)
|
CString::new(bytes).map_err(Error::custom)
|
||||||
.map_err(|e| Error::custom(format!("unexpected NULL at byte {}", e.nul_position())))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1005,12 +1005,12 @@ declare_error_tests! {
|
|||||||
&[
|
&[
|
||||||
Token::Bytes(b"a\0c"),
|
Token::Bytes(b"a\0c"),
|
||||||
],
|
],
|
||||||
Error::Message("unexpected NULL at byte 1".into()),
|
Error::Message("nul byte found in provided data at position: 1".into()),
|
||||||
}
|
}
|
||||||
test_cstring_internal_null_end<CString> {
|
test_cstring_internal_null_end<CString> {
|
||||||
&[
|
&[
|
||||||
Token::Bytes(b"ac\0"),
|
Token::Bytes(b"ac\0"),
|
||||||
],
|
],
|
||||||
Error::Message("unexpected NULL at byte 2".into()),
|
Error::Message("nul byte found in provided data at position: 2".into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user