use alloc::string::String;
use core::mem::{self, MaybeUninit};

// ABI compatible with C++ rust::String (not necessarily alloc::string::String).
#[repr(C)]
pub struct RustString {
    repr: [MaybeUninit<usize>; mem::size_of::<String>() / mem::size_of::<usize>()],
}

impl RustString {
    pub fn from(s: String) -> Self {
        unsafe { mem::transmute::<String, RustString>(s) }
    }

    pub fn from_ref(s: &String) -> &Self {
        unsafe { &*(s as *const String as *const RustString) }
    }

    pub fn from_mut(s: &mut String) -> &mut Self {
        unsafe { &mut *(s as *mut String as *mut RustString) }
    }

    pub fn into_string(self) -> String {
        unsafe { mem::transmute::<RustString, String>(self) }
    }

    pub fn as_string(&self) -> &String {
        unsafe { &*(self as *const RustString as *const String) }
    }

    pub fn as_mut_string(&mut self) -> &mut String {
        unsafe { &mut *(self as *mut RustString as *mut String) }
    }
}

const_assert_eq!(mem::size_of::<[usize; 3]>(), mem::size_of::<RustString>());
const_assert_eq!(mem::size_of::<String>(), mem::size_of::<RustString>());
const_assert_eq!(mem::align_of::<String>(), mem::align_of::<RustString>());

use alloc::string::String;
use core::mem;

#[repr(C)]
pub struct RustString {
    repr: String,
}

impl RustString {
    pub fn from(s: String) -> Self {
        RustString { repr: s }
    }

    pub fn from_ref(s: &String) -> &Self {
        unsafe { &*(s as *const String as *const RustString) }
    }

    pub fn from_mut(s: &mut String) -> &mut Self {
        unsafe { &mut *(s as *mut String as *mut RustString) }
    }

    pub fn into_string(self) -> String {
        self.repr
    }

    pub fn as_string(&self) -> &String {
        &self.repr
    }

    pub fn as_mut_string(&mut self) -> &mut String {
        &mut self.repr
    }
}

const_assert_eq!(mem::size_of::<[usize; 3]>(), mem::size_of::<String>());
const_assert_eq!(mem::align_of::<usize>(), mem::align_of::<String>());

--- 
+++ 
@@ -1,14 +1,15 @@
 use alloc::string::String;
-use core::mem;
+use core::mem::{self, MaybeUninit};
 
+// ABI compatible with C++ rust::String (not necessarily alloc::string::String).
 #[repr(C)]
 pub struct RustString {
-    repr: String,
+    repr: [MaybeUninit<usize>; mem::size_of::<String>() / mem::size_of::<usize>()],
 }
 
 impl RustString {
     pub fn from(s: String) -> Self {
-        RustString { repr: s }
+        unsafe { mem::transmute::<String, RustString>(s) }
     }
 
     pub fn from_ref(s: &String) -> &Self {
@@ -20,17 +21,18 @@
     }
 
     pub fn into_string(self) -> String {
-        self.repr
+        unsafe { mem::transmute::<RustString, String>(self) }
     }
 
     pub fn as_string(&self) -> &String {
-        &self.repr
+        unsafe { &*(self as *const RustString as *const String) }
     }
 
     pub fn as_mut_string(&mut self) -> &mut String {
-        &mut self.repr
+        unsafe { &mut *(self as *mut RustString as *mut String) }
     }
 }
 
-const_assert_eq!(mem::size_of::<[usize; 3]>(), mem::size_of::<String>());
-const_assert_eq!(mem::align_of::<usize>(), mem::align_of::<String>());
+const_assert_eq!(mem::size_of::<[usize; 3]>(), mem::size_of::<RustString>());
+const_assert_eq!(mem::size_of::<String>(), mem::size_of::<RustString>());
+const_assert_eq!(mem::align_of::<String>(), mem::align_of::<RustString>());
Resolve improper ctype lint affecting RustString
