Skip to content

Commit

Permalink
Consolidate unsafe RawValue transmutes in one place
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 17, 2021
1 parent dee8161 commit 4125560
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ impl RawValue {
fn from_owned(json: Box<str>) -> Box<Self> {
unsafe { mem::transmute::<Box<str>, Box<RawValue>>(json) }
}

fn into_owned(raw_value: Box<Self>) -> Box<str> {
unsafe { mem::transmute::<Box<RawValue>, Box<str>>(raw_value) }
}
}

impl Clone for Box<RawValue> {
Expand Down Expand Up @@ -217,8 +221,8 @@ impl RawValue {
}

impl From<Box<RawValue>> for Box<str> {
fn from(val: Box<RawValue>) -> Self {
unsafe { mem::transmute::<Box<RawValue>, Box<str>>(val) }
fn from(raw_value: Box<RawValue>) -> Self {
RawValue::into_owned(raw_value)
}
}

Expand Down

0 comments on commit 4125560

Please sign in to comment.