Skip to content

Commit 4125560

Browse files
committed
Consolidate unsafe RawValue transmutes in one place
1 parent dee8161 commit 4125560

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/raw.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ impl RawValue {
122122
fn from_owned(json: Box<str>) -> Box<Self> {
123123
unsafe { mem::transmute::<Box<str>, Box<RawValue>>(json) }
124124
}
125+
126+
fn into_owned(raw_value: Box<Self>) -> Box<str> {
127+
unsafe { mem::transmute::<Box<RawValue>, Box<str>>(raw_value) }
128+
}
125129
}
126130

127131
impl Clone for Box<RawValue> {
@@ -217,8 +221,8 @@ impl RawValue {
217221
}
218222

219223
impl From<Box<RawValue>> for Box<str> {
220-
fn from(val: Box<RawValue>) -> Self {
221-
unsafe { mem::transmute::<Box<RawValue>, Box<str>>(val) }
224+
fn from(raw_value: Box<RawValue>) -> Self {
225+
RawValue::into_owned(raw_value)
222226
}
223227
}
224228

0 commit comments

Comments
 (0)