From a45e0092cd91f5e92438a620cbd98c45fcf31f10 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 5 Feb 2025 10:08:32 -0500 Subject: [PATCH] minor cleanup --- platform/rust/build.rs | 2 +- .../{wrapper.h => tile_server_options.h} | 3 -- platform/rust/justfile | 2 +- platform/rust/src/lib.rs | 35 +++++++++---------- platform/rust/src/tile_server_options.rs | 4 +-- platform/rust/src/wrapper.cc | 6 +--- 6 files changed, 22 insertions(+), 30 deletions(-) rename platform/rust/include/{wrapper.h => tile_server_options.h} (99%) diff --git a/platform/rust/build.rs b/platform/rust/build.rs index 317ceee22cb..bab566874b8 100644 --- a/platform/rust/build.rs +++ b/platform/rust/build.rs @@ -42,5 +42,5 @@ fn main() { println!("cargo:rerun-if-changed=src/lib.rs"); println!("cargo:rerun-if-changed=src/wrapper.cc"); - println!("cargo:rerun-if-changed=include/wrapper.h"); + println!("cargo:rerun-if-changed=include/tile_server_options.h"); } diff --git a/platform/rust/include/wrapper.h b/platform/rust/include/tile_server_options.h similarity index 99% rename from platform/rust/include/wrapper.h rename to platform/rust/include/tile_server_options.h index c4b5c92b6fd..ef07e5acd7e 100644 --- a/platform/rust/include/wrapper.h +++ b/platform/rust/include/tile_server_options.h @@ -1,13 +1,10 @@ #pragma once #include "rust/cxx.h" -#include "mbgl/math/log2.hpp" #include "mbgl/util/tile_server_options.hpp" namespace ml { namespace bridge { -uint32_t get_42(); - using namespace mbgl; // TileServerOptions constructor helpers diff --git a/platform/rust/justfile b/platform/rust/justfile index 73f9da6514b..4c7f9bd7a32 100644 --- a/platform/rust/justfile +++ b/platform/rust/justfile @@ -57,7 +57,7 @@ docs: cargo doc --no-deps --open # Print Rust version information -rust-info: +@rust-info: rustc --version cargo --version diff --git a/platform/rust/src/lib.rs b/platform/rust/src/lib.rs index 73e25f29a72..1494beb202f 100644 --- a/platform/rust/src/lib.rs +++ b/platform/rust/src/lib.rs @@ -3,9 +3,8 @@ pub use tile_server_options::TileServerOptions; #[cxx::bridge(namespace = "ml::bridge")] mod ffi { - // C++ types exposed to Rust. unsafe extern "C++" { - include!("maplibre-native/include/wrapper.h"); + include!("maplibre-native/include/tile_server_options.h"); #[namespace = "mbgl"] type TileServerOptions; @@ -16,17 +15,17 @@ mod ffi { fn TileServerOptions_maptiler() -> UniquePtr; fn TileServerOptions_withBaseURL(obj: Pin<&mut TileServerOptions>, value: &str); - fn baseURL(self: &TileServerOptions) -> &CxxString; + fn baseURL(&self) -> &CxxString; fn TileServerOptions_withUriSchemeAlias(obj: Pin<&mut TileServerOptions>, value: &str); - fn uriSchemeAlias(self: &TileServerOptions) -> &CxxString; + fn uriSchemeAlias(&self) -> &CxxString; unsafe fn TileServerOptions_withSourceTemplate( obj: Pin<&mut TileServerOptions>, source_template: &str, domain_name: &str, version_prefix: *const i8, ); - fn sourceTemplate(self: &TileServerOptions) -> &CxxString; - fn sourceDomainName(self: &TileServerOptions) -> &CxxString; + fn sourceTemplate(&self) -> &CxxString; + fn sourceDomainName(&self) -> &CxxString; unsafe fn TileServerOptions_sourceVersionPrefix(value: &TileServerOptions) -> *const i8; unsafe fn TileServerOptions_withStyleTemplate( obj: Pin<&mut TileServerOptions>, @@ -34,8 +33,8 @@ mod ffi { domain_name: &str, version_prefix: *const i8, ); - fn styleTemplate(self: &TileServerOptions) -> &CxxString; - fn styleDomainName(self: &TileServerOptions) -> &CxxString; + fn styleTemplate(&self) -> &CxxString; + fn styleDomainName(&self) -> &CxxString; unsafe fn TileServerOptions_styleVersionPrefix(value: &TileServerOptions) -> *const i8; unsafe fn TileServerOptions_withSpritesTemplate( obj: Pin<&mut TileServerOptions>, @@ -43,8 +42,8 @@ mod ffi { domain_name: &str, version_prefix: *const i8, ); - fn spritesTemplate(self: &TileServerOptions) -> &CxxString; - fn spritesDomainName(self: &TileServerOptions) -> &CxxString; + fn spritesTemplate(&self) -> &CxxString; + fn spritesDomainName(&self) -> &CxxString; unsafe fn TileServerOptions_spritesVersionPrefix(value: &TileServerOptions) -> *const i8; unsafe fn TileServerOptions_withGlyphsTemplate( obj: Pin<&mut TileServerOptions>, @@ -52,8 +51,8 @@ mod ffi { domain_name: &str, version_prefix: *const i8, ); - fn glyphsTemplate(self: &TileServerOptions) -> &CxxString; - fn glyphsDomainName(self: &TileServerOptions) -> &CxxString; + fn glyphsTemplate(&self) -> &CxxString; + fn glyphsDomainName(&self) -> &CxxString; unsafe fn TileServerOptions_glyphsVersionPrefix(value: &TileServerOptions) -> *const i8; unsafe fn TileServerOptions_withTileTemplate( obj: Pin<&mut TileServerOptions>, @@ -61,16 +60,16 @@ mod ffi { domain_name: &str, version_prefix: *const i8, ); - fn tileTemplate(self: &TileServerOptions) -> &CxxString; - fn tileDomainName(self: &TileServerOptions) -> &CxxString; + fn tileTemplate(&self) -> &CxxString; + fn tileDomainName(&self) -> &CxxString; unsafe fn TileServerOptions_tileVersionPrefix(value: &TileServerOptions) -> *const i8; unsafe fn TileServerOptions_withApiKeyParameterName( obj: Pin<&mut TileServerOptions>, value: &str, ); - fn apiKeyParameterName(self: &TileServerOptions) -> &CxxString; + fn apiKeyParameterName(&self) -> &CxxString; fn TileServerOptions_setRequiresApiKey(obj: Pin<&mut TileServerOptions>, value: bool); - fn requiresApiKey(self: &TileServerOptions) -> bool; + fn requiresApiKey(&self) -> bool; // /// Gets the default styles. // const std::vector defaultStyles() const; @@ -78,8 +77,8 @@ mod ffi { // /// Sets the collection default styles. // TileServerOptions& withDefaultStyles(std::vector styles); - // fn withDefaultStyle(self: &TileServerOptions); + // fn withDefaultStyle(&self); unsafe fn TileServerOptions_withDefaultStyle(obj: Pin<&mut TileServerOptions>, value: &str); - fn defaultStyle(self: &TileServerOptions) -> &CxxString; + fn defaultStyle(&self) -> &CxxString; } } diff --git a/platform/rust/src/tile_server_options.rs b/platform/rust/src/tile_server_options.rs index e9a72838f60..0212e523ff6 100644 --- a/platform/rust/src/tile_server_options.rs +++ b/platform/rust/src/tile_server_options.rs @@ -14,8 +14,8 @@ pub struct TileServerOptions(UniquePtr); /// # Safety /// * as_ptr() inside C++ std::string is guaranteed to be null-terminated. /// * The &CStr will remain valid as long as the TileServerOptions `&self` remains valid. -/// If some code tries to modify self, it will need to use &mut self, -/// which will not compile unless there are no &CStr references, as they use the same lifetime. +/// If some code tries to modify self, it will need to use &mut self, +/// which will not compile unless there are no &CStr references, as they use the same lifetime. unsafe fn to_c_str(value: &CxxString) -> &CStr { CStr::from_ptr(value.as_ptr().cast()) } diff --git a/platform/rust/src/wrapper.cc b/platform/rust/src/wrapper.cc index 2a647f7bdff..be7c89adbdf 100644 --- a/platform/rust/src/wrapper.cc +++ b/platform/rust/src/wrapper.cc @@ -1,12 +1,8 @@ -#include "maplibre-native/include/wrapper.h" +#include "maplibre-native/include/tile_server_options.h" #include "maplibre-native/src/lib.rs.h" namespace ml { namespace bridge { -uint32_t get_42() { - return 42; -} - } // namespace bridge } // namespace ml