github dtolnay/cxx 1.0.54

latest releases: 1.0.122, 1.0.121, 1.0.120...
2 years ago
  • Enable C++ to reserve and read capacity on a rust::String (#924)

  • Enable Rust to reserve capacity on a CxxString (#925)

    This is important in APIs that connect bytes-based code in Rust to std::string-based code in C++.

    use bytes::Buf;
    use cxx::let_cxx_string;
    
    fn thing(buf: &mut dyn Buf) {
        let_cxx_string!(string = "");
    
        // handled by helper:
        string.as_mut().reserve(buf.remaining());
        while buf.remaining() > 0 {
            let chunk = buf.chunk();
            string.as_mut().push_bytes(chunk);
            buf.advance(chunk.len());
        }
    
        ffi::thing(string);
    }
    
    // ffi::thing:
    // void thing(std::string& s) {
    //   WriteMessage msg{std::move(s)};
    //   ...
    // }

Don't miss a new cxx release

NewReleases is sending notifications on new releases.