Use a free-standing function for the string_view to slice conversion

This commit is contained in:
Simon Hausmann 2021-03-19 13:13:08 +01:00
parent 0c21008861
commit 3bb4b87bc7
2 changed files with 11 additions and 11 deletions

View file

@ -103,15 +103,15 @@ fn gen_corelib(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> {
let mut string_config = config.clone();
string_config.export.exclude = vec!["SharedString".into()];
string_config.export.body.insert(
"Slice".to_owned(),
" static Slice<T> from_string(std::string_view str) {
return {
string_config.trailer = Some(
"namespace sixtyfps::private_api {
cbindgen_private::Slice<uint8_t> string_to_slice(std::string_view str) {
return cbindgen_private::Slice<uint8_t> {
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(str.data())),
str.size()
};
}"
.to_owned(),
}
}".to_owned(),
);
cbindgen::Builder::new()