diff --git a/api/sixtyfps-cpp/include/sixtyfps_string.h b/api/sixtyfps-cpp/include/sixtyfps_string.h index 208e47bbb..2537f8a80 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_string.h +++ b/api/sixtyfps-cpp/include/sixtyfps_string.h @@ -111,13 +111,21 @@ struct SharedString } friend bool operator<(const SharedString &a, const SharedString &b) - { return std::string_view(a) < std::string_view(b); } + { + return std::string_view(a) < std::string_view(b); + } friend bool operator<=(const SharedString &a, const SharedString &b) - { return std::string_view(a) <= std::string_view(b); } + { + return std::string_view(a) <= std::string_view(b); + } friend bool operator>(const SharedString &a, const SharedString &b) - { return std::string_view(a) > std::string_view(b); } + { + return std::string_view(a) > std::string_view(b); + } friend bool operator>=(const SharedString &a, const SharedString &b) - { return std::string_view(a) >= std::string_view(b); } + { + return std::string_view(a) >= std::string_view(b); + } /// Writes the \a shared_string to the specified \a stream and returns a reference to the /// stream. @@ -126,15 +134,18 @@ struct SharedString return stream << std::string_view(shared_string); } - friend SharedString operator+(const SharedString &a, std::string_view b) { + friend SharedString operator+(const SharedString &a, std::string_view b) + { SharedString a2 = a; return a2 += b; } - friend SharedString operator+(SharedString &&a, std::string_view b) { + friend SharedString operator+(SharedString &&a, std::string_view b) + { a += b; return a; } - SharedString &operator+=(std::string_view other) { + SharedString &operator+=(std::string_view other) + { cbindgen_private::sixtyfps_shared_string_append(this, other.data(), other.size()); return *this; } @@ -147,4 +158,14 @@ private: } void *inner; // opaque }; + +namespace private_api { +cbindgen_private::Slice string_to_slice(std::string_view str) +{ + return cbindgen_private::Slice { + const_cast(reinterpret_cast(str.data())), str.size() + }; +} +} + } diff --git a/xtask/src/cbindgen.rs b/xtask/src/cbindgen.rs index 96922af64..7e38adba6 100644 --- a/xtask/src/cbindgen.rs +++ b/xtask/src/cbindgen.rs @@ -103,17 +103,6 @@ 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.trailer = Some( - "namespace sixtyfps::private_api { - cbindgen_private::Slice string_to_slice(std::string_view str) { - return cbindgen_private::Slice { - const_cast(reinterpret_cast(str.data())), - str.size() - }; - } - }".to_owned(), - ); - cbindgen::Builder::new() .with_config(string_config) .with_src(crate_dir.join("string.rs"))