1use cxx::{let_cxx_string, CxxString}; 2use std::fmt::Write as _; 3 4#[test] 5fn test_async_cxx_string() { 6 async fn f() { 7 let_cxx_string!(s = "..."); 8 9 async fn g(_: &CxxString) {} 10 g(&s).await; 11 } 12 13 // https://github.com/dtolnay/cxx/issues/693 14 fn assert_send(_: impl Send) {} 15 assert_send(f()); 16} 17 18#[test] 19fn test_debug() { 20 let_cxx_string!(s = "x\"y\'z"); 21 22 assert_eq!(format!("{:?}", s), r#""x\"y'z""#); 23} 24 25#[test] 26fn test_fmt_write() { 27 let_cxx_string!(s = ""); 28 29 let name = "world"; 30 write!(s, "Hello, {name}!").unwrap(); 31 assert_eq!(s.to_str(), Ok("Hello, world!")); 32} 33 34#[test] 35fn test_io_write() { 36 let_cxx_string!(s = ""); 37 let mut reader: &[u8] = b"Hello, world!"; 38 39 std::io::copy(&mut reader, &mut s).unwrap(); 40 assert_eq!(s.to_str(), Ok("Hello, world!")); 41} 42