Skip to content

1.0.54

Choose a tag to compare

@dtolnay dtolnay released this 27 Aug 20:48
· 2021 commits to master since this release
1.0.54
fccef86
  • 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)};
    //   ...
    // }