dep-protobuf/rust/cpp_kernel/strings.cc
Protobuf Team Bot a9bc366522 Stop using double underscores for our C function names and standardize on the 'rust_proto_' prefix.
Besides unnecessary inconsistency on our C symbols, double underscores anywhere in the name are reserved for stdlib use.  In practice its unlikely these symbols would ever hit a collision problem (maybe the prior name 'utf8_debug_string' with no prefix as having some risk), but safer to just standardize on this and have no concerns going forward.

PiperOrigin-RevId: 648709299
2024-07-02 07:19:11 -07:00

26 lines
557 B
C++

#include "rust/cpp_kernel/strings.h"
#include <cstring>
#include <string>
#include "rust/cpp_kernel/rust_alloc_for_cpp_api.h"
namespace google {
namespace protobuf {
namespace rust_internal {
RustStringRawParts::RustStringRawParts(std::string src) {
if (src.empty()) {
data = nullptr;
len = 0;
} else {
void* d = rust_proto_alloc(src.length(), 1);
std::memcpy(d, src.data(), src.length());
data = static_cast<char*>(d);
len = src.length();
}
}
} // namespace rust_internal
} // namespace protobuf
} // namespace google