5555//! ```
5656//!
5757//! [serde]: https://serde.rs/
58-
58+ #! [ forbid ( unsafe_code ) ]
5959#![ warn( missing_debug_implementations, missing_docs) ]
6060
6161#[ macro_use]
6262extern crate serde;
6363
6464use std:: fmt:: { self , Display , Formatter } ;
65- use std:: mem;
6665use std:: str:: { self , Utf8Error } ;
6766
6867use serde:: de;
@@ -99,6 +98,7 @@ pub const MSGPACK_EXT_STRUCT_NAME: &str = "_ExtStruct";
9998///
10099/// Regardless of validity the UTF-8 content this type will always be serialized as a string.
101100#[ derive( Clone , Debug , PartialEq ) ]
101+ #[ doc( hidden) ]
102102pub struct Raw {
103103 s : Result < String , ( Vec < u8 > , Utf8Error ) > ,
104104}
@@ -111,7 +111,7 @@ impl Raw {
111111 }
112112
113113 /// DO NOT USE. See <https://github.com/3Hren/msgpack-rust/issues/305>
114- #[ deprecated( note = "This implementation is unsound and dangerous. See https://github.com/3Hren/msgpack-rust/issues/305 " ) ]
114+ #[ deprecated( note = "This feature has been removed " ) ]
115115 pub fn from_utf8 ( v : Vec < u8 > ) -> Self {
116116 match String :: from_utf8 ( v) {
117117 Ok ( v) => Raw :: new ( v) ,
@@ -185,14 +185,10 @@ impl Serialize for Raw {
185185 where
186186 S : serde:: Serializer
187187 {
188- let s = match self . s {
189- Ok ( ref s) => s. as_str ( ) ,
190- // FIXME: this is invalid. It should use a newtype hack instead.
191- // https://github.com/3Hren/msgpack-rust/issues/305
192- Err ( ( ref b, ..) ) => unsafe { mem:: transmute ( & b[ ..] ) } ,
193- } ;
194-
195- se. serialize_str ( s)
188+ match self . s {
189+ Ok ( ref s) => se. serialize_str ( s) ,
190+ Err ( ( ref b, ..) ) => se. serialize_bytes ( b) ,
191+ }
196192 }
197193}
198194
@@ -260,6 +256,7 @@ impl<'de> Deserialize<'de> for Raw {
260256///
261257/// Regardless of validity the UTF-8 content this type will always be serialized as a string.
262258#[ derive( Clone , Copy , Debug , PartialEq ) ]
259+ #[ doc( hidden) ]
263260pub struct RawRef < ' a > {
264261 s : Result < & ' a str , ( & ' a [ u8 ] , Utf8Error ) > ,
265262}
@@ -271,8 +268,7 @@ impl<'a> RawRef<'a> {
271268 Self { s : Ok ( v) }
272269 }
273270
274- /// DO NOT USE. See <https://github.com/3Hren/msgpack-rust/issues/305>
275- #[ deprecated( note = "This implementation is unsound and dangerous. See https://github.com/3Hren/msgpack-rust/issues/305" ) ]
271+ #[ deprecated( note = "This feature has been removed" ) ]
276272 pub fn from_utf8 ( v : & ' a [ u8 ] ) -> Self {
277273 match str:: from_utf8 ( v) {
278274 Ok ( v) => RawRef :: new ( v) ,
@@ -330,14 +326,10 @@ impl<'a> Serialize for RawRef<'a> {
330326 where
331327 S : serde:: Serializer ,
332328 {
333- let s = match self . s {
334- Ok ( ref s) => s,
335- // FIXME: this is invalid. It should use a newtype hack instead.
336- // https://github.com/3Hren/msgpack-rust/issues/305
337- Err ( ( ref b, ..) ) => unsafe { mem:: transmute ( b) } ,
338- } ;
339-
340- se. serialize_str ( s)
329+ match self . s {
330+ Ok ( ref s) => se. serialize_str ( s) ,
331+ Err ( ( ref b, ..) ) => se. serialize_bytes ( b) ,
332+ }
341333 }
342334}
343335
0 commit comments