1 use core::mem; 2 use core::ptr::NonNull; 3 use core::str; 4 5 #[repr(C)] 6 pub struct RustStr { 7 repr: NonNull<str>, 8 } 9 10 impl RustStr { from(repr: &str) -> Self11 pub fn from(repr: &str) -> Self { 12 let repr = NonNull::from(repr); 13 RustStr { repr } 14 } 15 as_str<'a>(self) -> &'a str16 pub unsafe fn as_str<'a>(self) -> &'a str { 17 &*self.repr.as_ptr() 18 } 19 } 20 21 const_assert_eq!(mem::size_of::<Option<RustStr>>(), mem::size_of::<RustStr>()); 22