From 5e10578f2d91366e14e11be2735a825054af7dd2 Mon Sep 17 00:00:00 2001 From: RedMser Date: Wed, 13 Nov 2024 22:14:00 +0100 Subject: [PATCH] Cargo: update all dependencies to latest version This fixes crashes with Godot v4.3 --- rust/Cargo.lock | 84 +++++++++++------------ rust/src/fluent/editor_plugin.rs | 9 +-- rust/src/fluent/export_plugin.rs | 8 +-- rust/src/fluent/extractor_packed_scene.rs | 20 +++--- rust/src/fluent/generator.rs | 16 ++--- rust/src/fluent/global.rs | 4 +- rust/src/fluent/importer.rs | 12 ++-- rust/src/fluent/locale.rs | 26 +++---- rust/src/fluent/project_settings.rs | 8 +-- rust/src/fluent/strip_comments.rs | 4 +- rust/src/fluent/translation.rs | 24 +++---- rust/src/hacks.rs | 4 ++ rust/src/lib.rs | 6 +- rust/src/utils.rs | 14 ++-- 14 files changed, 122 insertions(+), 117 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 9dbddba..dcb4e60 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -65,9 +65,9 @@ dependencies = [ [[package]] name = "constcat" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f2e5af989b1955b092db01462980c0a286217f86817e12b2c09aea46bd03651" +checksum = "4938185353434999ef52c81753c8cca8955ed38042fc29913db3751916f3b7ab" [[package]] name = "displaydoc" @@ -99,7 +99,7 @@ dependencies = [ [[package]] name = "fluent" version = "0.16.1" -source = "git+https://github.com/projectfluent/fluent-rs?branch=main#d7f0d48cb22d5a66934c492d29a96f694c438c7f" +source = "git+https://github.com/projectfluent/fluent-rs?branch=main#f2033ce8340e09000ad9efccd6215b3fa5c23496" dependencies = [ "fluent-bundle", "unic-langid", @@ -108,7 +108,7 @@ dependencies = [ [[package]] name = "fluent-bundle" version = "0.15.3" -source = "git+https://github.com/projectfluent/fluent-rs?branch=main#d7f0d48cb22d5a66934c492d29a96f694c438c7f" +source = "git+https://github.com/projectfluent/fluent-rs?branch=main#f2033ce8340e09000ad9efccd6215b3fa5c23496" dependencies = [ "fluent-langneg", "fluent-syntax", @@ -132,7 +132,7 @@ dependencies = [ [[package]] name = "fluent-syntax" version = "0.11.1" -source = "git+https://github.com/projectfluent/fluent-rs?branch=main#d7f0d48cb22d5a66934c492d29a96f694c438c7f" +source = "git+https://github.com/projectfluent/fluent-rs?branch=main#f2033ce8340e09000ad9efccd6215b3fa5c23496" dependencies = [ "memchr", "thiserror", @@ -140,8 +140,8 @@ dependencies = [ [[package]] name = "gdextension-api" -version = "0.2.0" -source = "git+https://github.com/godot-rust/godot4-prebuilt?branch=releases#6d902e8a6060007f4ab94cd78882247ae2558d96" +version = "0.2.1" +source = "git+https://github.com/godot-rust/godot4-prebuilt?branch=releases#53fa4a856d93ac01d87deb8f57c6851179dfacec" [[package]] name = "gensym" @@ -181,7 +181,7 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "godot" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#acae2b0faa110ca9be36bc77789b37481c5b4bdc" +source = "git+https://github.com/godot-rust/gdext?branch=master#f40fa274644c4ed5458fbc5fd6d587d8a3b9e4e3" dependencies = [ "godot-core", "godot-macros", @@ -190,7 +190,7 @@ dependencies = [ [[package]] name = "godot-bindings" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#acae2b0faa110ca9be36bc77789b37481c5b4bdc" +source = "git+https://github.com/godot-rust/gdext?branch=master#f40fa274644c4ed5458fbc5fd6d587d8a3b9e4e3" dependencies = [ "bindgen", "gdextension-api", @@ -201,12 +201,12 @@ dependencies = [ [[package]] name = "godot-cell" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#acae2b0faa110ca9be36bc77789b37481c5b4bdc" +source = "git+https://github.com/godot-rust/gdext?branch=master#f40fa274644c4ed5458fbc5fd6d587d8a3b9e4e3" [[package]] name = "godot-codegen" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#acae2b0faa110ca9be36bc77789b37481c5b4bdc" +source = "git+https://github.com/godot-rust/gdext?branch=master#f40fa274644c4ed5458fbc5fd6d587d8a3b9e4e3" dependencies = [ "godot-bindings", "heck", @@ -219,7 +219,7 @@ dependencies = [ [[package]] name = "godot-core" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#acae2b0faa110ca9be36bc77789b37481c5b4bdc" +source = "git+https://github.com/godot-rust/gdext?branch=master#f40fa274644c4ed5458fbc5fd6d587d8a3b9e4e3" dependencies = [ "glam", "godot-bindings", @@ -231,7 +231,7 @@ dependencies = [ [[package]] name = "godot-ffi" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#acae2b0faa110ca9be36bc77789b37481c5b4bdc" +source = "git+https://github.com/godot-rust/gdext?branch=master#f40fa274644c4ed5458fbc5fd6d587d8a3b9e4e3" dependencies = [ "gensym", "godot-bindings", @@ -255,7 +255,7 @@ dependencies = [ [[package]] name = "godot-macros" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#acae2b0faa110ca9be36bc77789b37481c5b4bdc" +source = "git+https://github.com/godot-rust/gdext?branch=master#f40fa274644c4ed5458fbc5fd6d587d8a3b9e4e3" dependencies = [ "godot-bindings", "markdown", @@ -282,7 +282,7 @@ dependencies = [ [[package]] name = "intl-memoizer" version = "0.5.2" -source = "git+https://github.com/projectfluent/fluent-rs?branch=main#d7f0d48cb22d5a66934c492d29a96f694c438c7f" +source = "git+https://github.com/projectfluent/fluent-rs?branch=main#f2033ce8340e09000ad9efccd6215b3fa5c23496" dependencies = [ "type-map", "unic-langid", @@ -320,9 +320,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "libloading" @@ -342,9 +342,9 @@ checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "markdown" -version = "1.0.0-alpha.20" +version = "1.0.0-alpha.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "911a8325e6fb87b89890cd4529a2ab34c2669c026279e61c26b7140a3d821ccb" +checksum = "a6491e6c702bf7e3b24e769d800746d5f2c06a6c6a2db7992612e0f429029e81" dependencies = [ "unicode-id", ] @@ -400,9 +400,9 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] @@ -418,9 +418,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.6" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -430,9 +430,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -441,9 +441,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rustc-hash" @@ -459,9 +459,9 @@ checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustix" -version = "0.38.36" +version = "0.38.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36" +checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" dependencies = [ "bitflags", "errno", @@ -490,9 +490,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.77" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -501,18 +501,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", @@ -557,21 +557,21 @@ dependencies = [ [[package]] name = "unicode-id" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1b6def86329695390197b82c1e244a54a131ceb66c996f2088a3876e2ae083f" +checksum = "10103c57044730945224467c09f71a4db0071c123a0648cc3e818913bde6b561" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "uuid" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" dependencies = [ "getrandom", ] diff --git a/rust/src/fluent/editor_plugin.rs b/rust/src/fluent/editor_plugin.rs index d05d9e5..026497a 100644 --- a/rust/src/fluent/editor_plugin.rs +++ b/rust/src/fluent/editor_plugin.rs @@ -15,12 +15,13 @@ impl IEditorPlugin for FluentEditorPlugin { fn enter_tree(&mut self) { let export_plugin = FluentExportPlugin::new_gd(); self.export_plugin = Some(export_plugin.clone()); - self.base_mut().add_export_plugin(export_plugin); + self.base_mut().add_export_plugin(&export_plugin); } fn exit_tree(&mut self) { - let export_plugin = self.export_plugin.take(); - self.base_mut().remove_export_plugin(export_plugin); - self.export_plugin = None; + if let Some(export_plugin) = self.export_plugin.take() { + self.base_mut().remove_export_plugin(&export_plugin); + self.export_plugin = None; + } } } diff --git a/rust/src/fluent/export_plugin.rs b/rust/src/fluent/export_plugin.rs index 86669b1..b9cb4b2 100644 --- a/rust/src/fluent/export_plugin.rs +++ b/rust/src/fluent/export_plugin.rs @@ -22,7 +22,7 @@ impl IEditorExportPlugin for FluentExportPlugin { } fn get_export_options(&self, _platform: Option>) -> Array { - array![dict! { + array![&dict! { "option": dict! { "name": GString::from(EXPORT_OPTION_STRIP_COMMENTS), "type": VariantType::BOOL, @@ -36,13 +36,13 @@ impl IEditorExportPlugin for FluentExportPlugin { return; } - if self.base().get_option(StringName::from(EXPORT_OPTION_STRIP_COMMENTS)).booleanize() { + if self.base().get_option(EXPORT_OPTION_STRIP_COMMENTS).booleanize() { // Strip comments from file - let contents = strip_comments(path.clone()); + let contents = strip_comments(&path); let binary = PackedByteArray::from_iter(contents.bytes()); self.base_mut().skip(); - self.base_mut().add_file(path, binary, false); + self.base_mut().add_file(&path, &binary, false); } } diff --git a/rust/src/fluent/extractor_packed_scene.rs b/rust/src/fluent/extractor_packed_scene.rs index 0efc230..d3ddac1 100644 --- a/rust/src/fluent/extractor_packed_scene.rs +++ b/rust/src/fluent/extractor_packed_scene.rs @@ -16,14 +16,14 @@ pub struct FluentPackedSceneTranslationParser { /// Main difference is that it does not (yet) call parsers recursively. impl FluentTranslationParser for FluentPackedSceneTranslationParser { fn get_recognized_extensions(&self) -> Vec { - ResourceLoader::singleton().get_recognized_extensions_for_type("PackedScene".into()).to_vec() + ResourceLoader::singleton().get_recognized_extensions_for_type("PackedScene").to_vec() } fn extract_messages(&self, path: &GString) -> MessageGeneration { let class_db = ClassDb::singleton(); - let loaded_res = ResourceLoader::singleton().load_ex(path.clone()) - .type_hint("PackedScene".into()) + let loaded_res = ResourceLoader::singleton().load_ex(path) + .type_hint("PackedScene") .cache_mode(CacheMode::REUSE) .done(); if loaded_res.is_none() { @@ -92,7 +92,7 @@ impl FluentTranslationParser for FluentPackedSceneTranslationParser { tabcontainer_paths.pop(); } - if auto_translating && !tabcontainer_paths.is_empty() && class_db.is_parent_class(node_type.clone(), "Control".into()) + if auto_translating && !tabcontainer_paths.is_empty() && class_db.is_parent_class(&node_type, "Control") && GString::from(parent_path) == tabcontainer_paths[((tabcontainer_paths.len() as i64) - 1) as usize] { parsed_strings.push(GString::from(state.get_node_name(i))); } @@ -162,7 +162,7 @@ impl FluentTranslationParser for FluentPackedSceneTranslationParser { impl FluentPackedSceneTranslationParser { pub fn init() -> Self { let lookup_properties = ["^text$", "^.+_text$", "^popup/.+/text$", "^title$", "^filters$", /* "^script$", */] - .map(|str| RegEx::create_from_string(str.into()).unwrap()) + .map(|str| RegEx::create_from_string(str).unwrap()) .into(); let exception_list = [ ("LineEdit", ["^text$"]), @@ -170,7 +170,7 @@ impl FluentPackedSceneTranslationParser { ("CodeEdit", ["^text$"]), ].map(|(typename, strs)| (StringName::from(typename), HashSet::from( - strs.map(|str| RegEx::create_from_string(str.into()).unwrap()) + strs.map(|str| RegEx::create_from_string(str).unwrap()) )) ) .into(); @@ -185,20 +185,20 @@ impl FluentPackedSceneTranslationParser { let class_db = ClassDb::singleton(); for (exception_node_type, exception_properties) in &self.exception_list { - if class_db.is_parent_class(node_type.clone(), exception_node_type.clone()) && + if class_db.is_parent_class(node_type, exception_node_type) && exception_properties.iter().any(|exception_property| - Self::matches(GString::from(property_name), exception_property.clone()) + Self::matches(&GString::from(property_name), exception_property.clone()) ) { return false; } } self.lookup_properties.iter().any(|lookup_property| - Self::matches(GString::from(property_name), lookup_property.clone()) + Self::matches(&GString::from(property_name), lookup_property.clone()) ) } - fn matches(string: GString, pattern: Gd) -> bool { + fn matches(string: &GString, pattern: Gd) -> bool { pattern.search(string).is_some() } } diff --git a/rust/src/fluent/generator.rs b/rust/src/fluent/generator.rs index 413d6aa..f3319c5 100644 --- a/rust/src/fluent/generator.rs +++ b/rust/src/fluent/generator.rs @@ -34,19 +34,19 @@ impl FluentGenerator { #[func] pub fn create() -> Gd { let project_settings = ProjectSettings::singleton(); - let locales = PackedStringArray::from_variant(&project_settings.get_setting(PROJECT_SETTING_GENERATOR_LOCALES.into())); + let locales = PackedStringArray::from_variant(&project_settings.get_setting(PROJECT_SETTING_GENERATOR_LOCALES)); let locales = locales.as_slice().iter().map(|s| s.to_string()).collect(); - let file_patterns = Dictionary::from_variant(&project_settings.get_setting(PROJECT_SETTING_GENERATOR_PATTERNS.into())); + let file_patterns = Dictionary::from_variant(&project_settings.get_setting(PROJECT_SETTING_GENERATOR_PATTERNS)); let file_patterns = file_patterns.iter_shared().map(|(k, v)| { let k = GString::from_variant(&k); - let k = RegEx::create_from_string(k).unwrap(); + let k = RegEx::create_from_string(&k).unwrap(); let v = GString::from_variant(&v).to_string(); (k, v) }).collect(); Gd::from_object(Self { locales, file_patterns, - invalid_message_handling: i32::from_variant(&project_settings.get_setting(PROJECT_SETTING_GENERATOR_INVALID_MESSAGE_HANDLING.into())), + invalid_message_handling: i32::from_variant(&project_settings.get_setting(PROJECT_SETTING_GENERATOR_INVALID_MESSAGE_HANDLING)), extractor: FluentPackedSceneTranslationParser::init(), }) } @@ -100,7 +100,7 @@ impl FluentGenerator { .filter_map(|str| { // Check all patterns until the first matches (returns Some(RegExMatch)). self.file_patterns.iter().find_map(|(regex, pattern)| { - let regex_match = regex.search(str.clone()); + let regex_match = regex.search(&str); if regex_match.is_none() { return None; } @@ -124,7 +124,7 @@ impl FluentGenerator { .map(|locale| { let mut pattern = pattern.replace("{$locale}", locale); for group_index in 0..=source_match.get_group_count() { - let group_value = source_match.get_string_ex().name(group_index.to_variant()).done(); + let group_value = source_match.get_string_ex().name(&group_index.to_variant()).done(); pattern = pattern.replace(&format!("{{${}}}", group_index), &group_value.to_string()); } pattern @@ -135,7 +135,7 @@ impl FluentGenerator { fn create_or_update_ftl(path: String, messages: MessageGeneration) { // Load existing or create new FTL file. - let fa = create_or_open_file_for_read_write(path.clone().into()); + let fa = create_or_open_file_for_read_write(&path.clone().into()); if fa.is_err() { godot_error!("Unable to open file {} for writing: {}", path, error_string(fa.err().unwrap().ord() as i64)); return; @@ -214,7 +214,7 @@ impl FluentGenerator { godot_error!("Failed to resize file {}", path); return; } - fa.store_string(ftl.into()); + fa.store_string(&ftl); } fn make_safe_identifier(name: String) -> String { diff --git a/rust/src/fluent/global.rs b/rust/src/fluent/global.rs index a733001..fffb698 100644 --- a/rust/src/fluent/global.rs +++ b/rust/src/fluent/global.rs @@ -14,10 +14,10 @@ impl FluentI18nSingleton { pub(crate) const SINGLETON_NAME: &'static str = "FluentI18nSingleton"; pub(crate) fn register(&self) { - ResourceLoader::singleton().add_resource_format_loader(self.loader.clone()); + ResourceLoader::singleton().add_resource_format_loader(&self.loader); } pub(crate) fn unregister(&self) { - ResourceLoader::singleton().remove_resource_format_loader(self.loader.clone()); + ResourceLoader::singleton().remove_resource_format_loader(&self.loader); } } diff --git a/rust/src/fluent/importer.rs b/rust/src/fluent/importer.rs index 8dfa80c..d0ae89f 100644 --- a/rust/src/fluent/importer.rs +++ b/rust/src/fluent/importer.rs @@ -24,7 +24,7 @@ impl IResourceFormatLoader for ResourceFormatLoaderFluent { } fn get_recognized_extensions(&self) -> PackedStringArray { - PackedStringArray::from(&["ftl".into_godot()]) + PackedStringArray::from(&["ftl".to_godot()]) } fn handles_type(&self, type_name: StringName) -> bool { @@ -47,25 +47,25 @@ impl IResourceFormatLoader for ResourceFormatLoaderFluent { return GdErr::ERR_INVALID_PARAMETER.ord().to_variant(); } - let text = FileAccess::get_file_as_string(path); + let text = FileAccess::get_file_as_string(&path); let err = FileAccess::get_open_error(); if err != GdErr::OK { return err.ord().to_variant(); } let mut translation = TranslationFluent::new_gd(); - translation.bind_mut().base_mut().set_locale(locale.unwrap().into()); + translation.bind_mut().base_mut().set_locale(&locale.unwrap()); let pattern_match = compute_message_pattern(&path_buf); if let Some(pattern_match) = pattern_match { - let mut pattern_target = String::from_godot(ProjectSettings::singleton().get_setting(PROJECT_SETTING_LOADER_MESSAGE_PATTERN.into()).stringify()); + let mut pattern_target = String::from_godot(ProjectSettings::singleton().get_setting(PROJECT_SETTING_LOADER_MESSAGE_PATTERN).stringify()); for group_index in 0..=pattern_match.get_group_count() { - let group_value = pattern_match.get_string_ex().name(group_index.to_variant()).done(); + let group_value = pattern_match.get_string_ex().name(&group_index.to_variant()).done(); pattern_target = pattern_target.replace(&format!("{{${}}}", group_index), &group_value.to_string()); } let pattern_target = GString::from(pattern_target); - let pattern_regex = RegEx::create_from_string(pattern_target.clone()).unwrap(); + let pattern_regex = RegEx::create_from_string(&pattern_target).unwrap(); if pattern_regex.get_group_count() != 1 { godot_warn!( "Expected {} to have exactly one capture group, but got {} instead.\nIgnoring message pattern!", diff --git a/rust/src/fluent/locale.rs b/rust/src/fluent/locale.rs index 06ff1f1..c29fcc2 100644 --- a/rust/src/fluent/locale.rs +++ b/rust/src/fluent/locale.rs @@ -12,32 +12,32 @@ pub fn compute_message_pattern(path: &PathBuf) -> Option> { let project_settings = ProjectSettings::singleton(); // Requires pattern string as well. - if project_settings.get_setting(PROJECT_SETTING_LOADER_MESSAGE_PATTERN.into()).stringify().is_empty() { + if project_settings.get_setting(PROJECT_SETTING_LOADER_MESSAGE_PATTERN).stringify().is_empty() { return None; } // 1. File regex. - let file_regex = project_settings.get_setting(PROJECT_SETTING_LOADER_PATTERN_BY_FILE_REGEX.into()).stringify(); + let file_regex = project_settings.get_setting(PROJECT_SETTING_LOADER_PATTERN_BY_FILE_REGEX).stringify(); if !file_regex.is_empty() { let file_name = path.file_name()?; let file_name = GString::from(file_name.to_owned().into_string().unwrap()); - let file_regex = RegEx::create_from_string(file_regex).unwrap(); - if let Some(regex_match) = file_regex.search(file_name) { + let file_regex = RegEx::create_from_string(&file_regex).unwrap(); + if let Some(regex_match) = file_regex.search(&file_name) { return Some(regex_match); } } // 2. Folder regex. - let folder_regex = project_settings.get_setting(PROJECT_SETTING_LOADER_PATTERN_BY_FOLDER_REGEX.into()).stringify(); + let folder_regex = project_settings.get_setting(PROJECT_SETTING_LOADER_PATTERN_BY_FOLDER_REGEX).stringify(); if !folder_regex.is_empty() { - let folder_regex = RegEx::create_from_string(folder_regex).unwrap(); + let folder_regex = RegEx::create_from_string(&folder_regex).unwrap(); for folder in path.iter().rev() { let folder = folder.to_owned().into_string().unwrap(); if folder == path::MAIN_SEPARATOR_STR { continue; } - if let Some(regex_match) = folder_regex.search(folder.into()) { + if let Some(regex_match) = folder_regex.search(&folder) { return Some(regex_match); } } @@ -51,14 +51,14 @@ pub fn compute_locale(path: &PathBuf) -> Option { let project_settings = ProjectSettings::singleton(); // 1. File regex. - let file_regex = project_settings.get_setting(PROJECT_SETTING_LOADER_LOCALE_BY_FILE_REGEX.into()).stringify(); + let file_regex = project_settings.get_setting(PROJECT_SETTING_LOADER_LOCALE_BY_FILE_REGEX).stringify(); if !file_regex.is_empty() { let file_name = path.file_name()?; let file_name = GString::from(file_name.to_owned().into_string().unwrap()); // Force regex to be case insensitive. let file_regex = "(?i)".to_owned() + &file_regex.to_string(); - let file_regex = RegEx::create_from_string(file_regex.into()).unwrap(); - if let Some(regex_match) = file_regex.search(file_name) { + let file_regex = RegEx::create_from_string(&file_regex).unwrap(); + if let Some(regex_match) = file_regex.search(&file_name) { let locale = get_single_regex_match(regex_match, PROJECT_SETTING_LOADER_LOCALE_BY_FILE_REGEX).to_string(); if is_valid_locale(&locale) { return Some(locale); @@ -67,18 +67,18 @@ pub fn compute_locale(path: &PathBuf) -> Option { } // 2. Folder regex. - let folder_regex = project_settings.get_setting(PROJECT_SETTING_LOADER_LOCALE_BY_FOLDER_REGEX.into()).stringify(); + let folder_regex = project_settings.get_setting(PROJECT_SETTING_LOADER_LOCALE_BY_FOLDER_REGEX).stringify(); if !folder_regex.is_empty() { // Force regex to be case insensitive. let folder_regex = "(?i)".to_owned() + &folder_regex.to_string(); - let folder_regex = RegEx::create_from_string(folder_regex.into()).unwrap(); + let folder_regex = RegEx::create_from_string(&folder_regex).unwrap(); for folder in path.iter().rev() { let folder = folder.to_owned().into_string().unwrap(); if folder == path::MAIN_SEPARATOR_STR { continue; } - if let Some(regex_match) = folder_regex.search(folder.into()) { + if let Some(regex_match) = folder_regex.search(&folder) { let locale = get_single_regex_match(regex_match, PROJECT_SETTING_LOADER_LOCALE_BY_FOLDER_REGEX).to_string(); if is_valid_locale(&locale) { return Some(locale); diff --git a/rust/src/fluent/project_settings.rs b/rust/src/fluent/project_settings.rs index 671e66e..b3b8277 100644 --- a/rust/src/fluent/project_settings.rs +++ b/rust/src/fluent/project_settings.rs @@ -40,8 +40,8 @@ fn register_setting(name: String, value: Variant) { fn register_setting_hint(name: String, value: Variant, hint: PropertyHint, hint_string: String) { let mut project_settings = ProjectSettings::singleton(); - if !project_settings.has_setting(name.clone().into()) { - project_settings.set_setting(name.clone().into(), value.clone()); + if !project_settings.has_setting(&name) { + project_settings.set_setting(&name, &value); } let mut property_info = Dictionary::new(); @@ -50,6 +50,6 @@ fn register_setting_hint(name: String, value: Variant, hint: PropertyHint, hint_ property_info.set("hint", hint); property_info.set("hint_string", GString::from(hint_string)); - project_settings.add_property_info(property_info); - project_settings.set_initial_value(GString::from(name), value); + project_settings.add_property_info(&property_info); + project_settings.set_initial_value(&name, &value); } diff --git a/rust/src/fluent/strip_comments.rs b/rust/src/fluent/strip_comments.rs index 44d48cf..c88e976 100644 --- a/rust/src/fluent/strip_comments.rs +++ b/rust/src/fluent/strip_comments.rs @@ -2,8 +2,8 @@ use godot::prelude::*; use fluent_syntax::{ast, parser::parse, serializer::serialize}; use godot::classes::FileAccess; -pub fn strip_comments(path: GString) -> String { - let contents = FileAccess::get_file_as_string(path.clone()); +pub fn strip_comments(path: &GString) -> String { + let contents = FileAccess::get_file_as_string(path); let ftl = parse(contents.to_string()); let mut ftl = match ftl { Ok(ftl) => ftl, diff --git a/rust/src/fluent/translation.rs b/rust/src/fluent/translation.rs index 89f0b1b..5e4bda2 100644 --- a/rust/src/fluent/translation.rs +++ b/rust/src/fluent/translation.rs @@ -41,7 +41,7 @@ impl ITranslation for TranslationFluent { std::mem::forget(base.to_gd()); // Default to an empty locale, so that it must be explicitly specified when loading a FTL file. - base.to_gd().set_locale(GString::new()); + base.to_gd().set_locale(&GString::new()); Self { message_pattern: GString::new(), @@ -79,7 +79,7 @@ impl TranslationFluent { self.message_pattern_regex = if value.is_empty() { None } else { - RegEx::create_from_string(value) + RegEx::create_from_string(&value) }; } @@ -92,7 +92,7 @@ impl TranslationFluent { if let Some(regex) = &self.message_pattern_regex { // Get actual message and see if it matches. - if let Some(regex_match) = regex.search(msg.into()) { + if let Some(regex_match) = regex.search(msg.arg()) { msg = get_single_regex_match(regex_match, "message_pattern").into(); } else { // Did not match, can not translate. @@ -147,15 +147,15 @@ impl TranslationFluent { fn fluent_to_variant(input: &FluentValue) -> Variant { match input { - FluentValue::String(str) => str.into_godot().to_variant(), + FluentValue::String(str) => str.clone().into_owned().to_godot().to_variant(), FluentValue::Number(num) => { // TODO: unsure what the default value for maximum_fraction_digits is, but likely not zero if let Some(0) = num.options.maximum_fraction_digits { // int - (num.value as i64).into_godot().to_variant() + (num.value as i64).to_godot().to_variant() } else { // float - num.value.into_godot().to_variant() + num.value.to_godot().to_variant() } }, FluentValue::Custom(_custom) => todo!("Custom FluentValue conversion"), @@ -241,7 +241,7 @@ impl TranslationFluent { /// This method is only needed when using the default version of the add-on, as the forked build includes an additional `args` parameter to the different translation methods. #[func] pub fn args(msg: StringName, args: Dictionary) -> StringName { - let args = var_to_str(Variant::from(args)).to_string(); + let args = var_to_str(&Variant::from(args)).to_string(); let msg = msg.to_string() + &args; msg.into() } @@ -249,7 +249,7 @@ impl TranslationFluent { fn extract_args(msg: StringName) -> (StringName, Dictionary) { let parse_args_in_message = { let project_settings = ProjectSettings::singleton(); - bool::from_variant(&project_settings.get_setting(PROJECT_SETTING_PARSE_ARGS_IN_MESSAGE.into())) + bool::from_variant(&project_settings.get_setting(PROJECT_SETTING_PARSE_ARGS_IN_MESSAGE)) }; if parse_args_in_message { // Try parsing trailing dict as args. @@ -258,7 +258,7 @@ impl TranslationFluent { let open_brace = msg_str.rfind('{'); if let Some(open_brace) = open_brace { let args = &msg_str[open_brace..]; - let args = str_to_var(args.into()); + let args = str_to_var(args); if args.get_type() != VariantType::DICTIONARY { return (msg, Default::default()); } @@ -311,7 +311,7 @@ impl TranslationFluent { fn create_bundle(&self) -> Result, GdErr> { let mut bundle = FluentBundle::new(self.get_fluent_locales()?); let project_settings = ProjectSettings::singleton(); - bundle.set_use_isolating(bool::from_variant(&project_settings.get_setting(PROJECT_SETTING_UNICODE_ISOLATION.into()))); + bundle.set_use_isolating(bool::from_variant(&project_settings.get_setting(PROJECT_SETTING_UNICODE_ISOLATION))); Ok(bundle) } @@ -331,7 +331,7 @@ impl TranslationFluent { let project_settings = ProjectSettings::singleton(); let mut locales = vec![lang_id]; // Use TranslationServer fallback if it exists (same check as TS::translate). - let fallback_locale = project_settings.get_setting(PROJECT_SETTING_FALLBACK_LOCALE.into()).stringify(); + let fallback_locale = project_settings.get_setting(PROJECT_SETTING_FALLBACK_LOCALE).stringify(); if fallback_locale.len() >= 2 { let fallback_locale_id = fallback_locale.to_string().parse::(); match fallback_locale_id { @@ -383,7 +383,7 @@ impl TranslationFluent { // Run the function and convert its result. let args = varray![positional_variants, named_variants]; - let result = callable.callv(args); + let result = callable.callv(&args); let result_variant = Self::variant_to_fluent(result); result_variant }); diff --git a/rust/src/hacks.rs b/rust/src/hacks.rs index 9e91642..1cac3f2 100644 --- a/rust/src/hacks.rs +++ b/rust/src/hacks.rs @@ -42,4 +42,8 @@ impl ToGodot for SyncSendCallable { fn to_godot(&self) -> Self::Via { self.0.to_godot() } + + type ToVia<'v> = Callable + where + Self: 'v; } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 45c9298..7fa9e6e 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -29,7 +29,7 @@ unsafe impl ExtensionLibrary for FluentI18n { singleton.bind().register(); Engine::singleton() - .register_singleton(FluentI18nSingleton::SINGLETON_NAME.into(), singleton); + .register_singleton(FluentI18nSingleton::SINGLETON_NAME, &singleton); } } @@ -38,10 +38,10 @@ unsafe impl ExtensionLibrary for FluentI18n { let mut engine = Engine::singleton(); let singleton = engine - .get_singleton(FluentI18nSingleton::SINGLETON_NAME.into()) + .get_singleton(FluentI18nSingleton::SINGLETON_NAME) .unwrap(); - engine.unregister_singleton(FluentI18nSingleton::SINGLETON_NAME.into()); + engine.unregister_singleton(FluentI18nSingleton::SINGLETON_NAME); singleton .clone() diff --git a/rust/src/utils.rs b/rust/src/utils.rs index 692fafe..50187e3 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -8,7 +8,7 @@ use godot::prelude::*; use godot::global::Error as GdErr; pub fn get_files_recursive(path: GString) -> Vec { - let da = DirAccess::open(path.clone()); + let da = DirAccess::open(&path); if da.is_none() || DirAccess::get_open_error() != GdErr::OK { godot_error!("Unable to recurse through folder {}: {}", path, error_string(DirAccess::get_open_error().ord() as i64)); return vec![]; @@ -24,7 +24,7 @@ pub fn get_files_recursive(path: GString) -> Vec { if da.current_is_dir() { if &file_name.to_string() != ".godot" { // TODO: use GString.path_join() once available (upstream issue) - let child_path = format!("{}/{}", path.clone(), file_name.clone()).into(); + let child_path = format!("{}/{}", path, file_name.clone()).into(); let mut recurse = get_files_recursive(child_path); files.append(&mut recurse); } @@ -36,20 +36,20 @@ pub fn get_files_recursive(path: GString) -> Vec { files } -pub fn create_or_open_file_for_read_write(path: GString) -> Result, GdErr> { +pub fn create_or_open_file_for_read_write(path: &GString) -> Result, GdErr> { let dir_only = match PathBuf::from(path.clone().to_string()).parent() { Some(dir) => dir.to_str().unwrap_or_default().into(), None => String::new(), }; - let dir_err = DirAccess::make_dir_recursive_absolute(dir_only.into()); + let dir_err = DirAccess::make_dir_recursive_absolute(&dir_only); if dir_err != GdErr::OK { return Err(dir_err); } - let fa = FileAccess::open(path.clone(), ModeFlags::READ_WRITE); + let fa = FileAccess::open(path, ModeFlags::READ_WRITE); if fa.is_none() || FileAccess::get_open_error() != GdErr::OK { if FileAccess::get_open_error() == GdErr::ERR_FILE_NOT_FOUND { - let fa = FileAccess::open(path.clone(), ModeFlags::WRITE_READ); + let fa = FileAccess::open(path, ModeFlags::WRITE_READ); if fa.is_some() && FileAccess::get_open_error() == GdErr::OK { return Ok(fa.unwrap()); } @@ -69,5 +69,5 @@ pub fn get_single_regex_match(regex_match: Gd, err_sourc } // Get the last capture group's value. - regex_match.get_string_ex().name(regex_match.get_group_count().to_variant()).done() + regex_match.get_string_ex().name(®ex_match.get_group_count().to_variant()).done() }