Skip to content

Commit

Permalink
Deprecate unsound RawRef newtype
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Apr 19, 2022
1 parent acfbdb3 commit 78f4817
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions rmp-serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ impl Raw {
Self { s: Ok(v) }
}

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

Expand Down Expand Up @@ -266,7 +269,8 @@ impl<'a> RawRef<'a> {
Self { s: Ok(v) }
}

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

Expand Down

0 comments on commit 78f4817

Please sign in to comment.