mirror of https://github.com/rwf2/Rocket.git
Use '#[repr(C)]' on 'str' wrappers to guarantee correct layout.
Closes #494.
This commit is contained in:
parent
94c7a1997e
commit
6460be62c3
|
@ -46,6 +46,7 @@ use http::uncased::UncasedStr;
|
||||||
///
|
///
|
||||||
/// [`FromParam`]: /rocket/request/trait.FromParam.html
|
/// [`FromParam`]: /rocket/request/trait.FromParam.html
|
||||||
/// [`FromFormValue`]: /rocket/request/trait.FromFormValue.html
|
/// [`FromFormValue`]: /rocket/request/trait.FromFormValue.html
|
||||||
|
#[repr(C)]
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct RawStr(str);
|
pub struct RawStr(str);
|
||||||
|
|
||||||
|
@ -276,7 +277,7 @@ impl RawStr {
|
||||||
impl<'a> From<&'a str> for &'a RawStr {
|
impl<'a> From<&'a str> for &'a RawStr {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn from(string: &'a str) -> &'a RawStr {
|
fn from(string: &'a str) -> &'a RawStr {
|
||||||
unsafe { ::std::mem::transmute(string) }
|
unsafe { &*(string as *const str as *const RawStr) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ use std::fmt;
|
||||||
///
|
///
|
||||||
/// let ascii_ref: &UncasedStr = "Hello, world!".into();
|
/// let ascii_ref: &UncasedStr = "Hello, world!".into();
|
||||||
/// ```
|
/// ```
|
||||||
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UncasedStr(str);
|
pub struct UncasedStr(str);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue