Skip to content

Commit 78f4817

Browse files
committed
Deprecate unsound RawRef newtype
#305
1 parent acfbdb3 commit 78f4817

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

rmp-serde/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ impl Raw {
108108
Self { s: Ok(v) }
109109
}
110110

111-
/// Converts a vector of bytes to a `Raw`.
111+
/// DO NOT USE. See <https://github.com/3Hren/msgpack-rust/issues/305>
112+
#[deprecated(note = "This implementation is unsound and dangerous. See https://github.com/3Hren/msgpack-rust/issues/305")]
112113
pub fn from_utf8(v: Vec<u8>) -> Self {
113114
match String::from_utf8(v) {
114115
Ok(v) => Raw::new(v),
@@ -184,6 +185,8 @@ impl Serialize for Raw {
184185
{
185186
let s = match self.s {
186187
Ok(ref s) => s.as_str(),
188+
// FIXME: this is invalid. It should use a newtype hack instead.
189+
// https://github.com/3Hren/msgpack-rust/issues/305
187190
Err((ref b, ..)) => unsafe { mem::transmute(&b[..]) },
188191
};
189192

@@ -266,7 +269,8 @@ impl<'a> RawRef<'a> {
266269
Self { s: Ok(v) }
267270
}
268271

269-
/// Converts a vector of bytes to a `RawRef`.
272+
/// DO NOT USE. See <https://github.com/3Hren/msgpack-rust/issues/305>
273+
#[deprecated(note = "This implementation is unsound and dangerous. See https://github.com/3Hren/msgpack-rust/issues/305")]
270274
pub fn from_utf8(v: &'a [u8]) -> Self {
271275
match str::from_utf8(v) {
272276
Ok(v) => RawRef::new(v),
@@ -326,6 +330,8 @@ impl<'a> Serialize for RawRef<'a> {
326330
{
327331
let s = match self.s {
328332
Ok(ref s) => s,
333+
// FIXME: this is invalid. It should use a newtype hack instead.
334+
// https://github.com/3Hren/msgpack-rust/issues/305
329335
Err((ref b, ..)) => unsafe { mem::transmute(b) },
330336
};
331337

0 commit comments

Comments
 (0)