1 #[cfg(feature = "alloc")] 2 use alloc::string::String; 3 use core::mem::MaybeUninit; 4 use core::ptr; 5 use core::slice; 6 use core::str; 7 8 #[export_name = "cxxbridge1$str$new"] 9 unsafe extern "C" fn str_new(this: &mut MaybeUninit<&str>) { 10 let this = this.as_mut_ptr(); 11 unsafe { ptr::write(this, "") } 12 } 13 14 #[cfg(feature = "alloc")] 15 #[export_name = "cxxbridge1$str$ref"] 16 unsafe extern "C" fn str_ref<'a>(this: &mut MaybeUninit<&'a str>, string: &'a String) { 17 let this = this.as_mut_ptr(); 18 let s = string.as_str(); 19 unsafe { ptr::write(this, s) } 20 } 21 22 #[export_name = "cxxbridge1$str$from"] 23 unsafe extern "C" fn str_from(this: &mut MaybeUninit<&str>, ptr: *const u8, len: usize) -> bool { 24 let slice = unsafe { slice::from_raw_parts(ptr, len) }; 25 match str::from_utf8(slice) { 26 Ok(s) => { 27 let this = this.as_mut_ptr(); 28 unsafe { ptr::write(this, s) } 29 true 30 } 31 Err(_) => false, 32 } 33 } 34 35 #[export_name = "cxxbridge1$str$ptr"] 36 unsafe extern "C" fn str_ptr(this: &&str) -> *const u8 { 37 this.as_ptr() 38 } 39 40 #[export_name = "cxxbridge1$str$len"] 41 unsafe extern "C" fn str_len(this: &&str) -> usize { 42 this.len() 43 } 44