Skip to content

Commit 4c8ea83

Browse files
authored
Merge pull request #775 from godot-rust/qol/cow-strings
Use `Cow<'static, str>`, following prebuilt upstream
2 parents cd31a83 + 21994cb commit 4c8ea83

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

godot-bindings/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ mod godot_version;
4949
#[path = ""]
5050
mod depend_on_custom {
5151
use super::*;
52+
use std::borrow::Cow;
5253

5354
pub(crate) mod godot_exe;
5455
pub(crate) mod godot_version;
5556
pub(crate) mod header_gen;
5657

57-
pub fn load_gdextension_json(watch: &mut StopWatch) -> String {
58-
godot_exe::load_gdextension_json(watch)
58+
pub fn load_gdextension_json(watch: &mut StopWatch) -> Cow<'static, str> {
59+
Cow::Owned(godot_exe::load_gdextension_json(watch))
5960
}
6061

6162
pub fn write_gdextension_headers(h_path: &Path, rs_path: &Path, watch: &mut StopWatch) {
@@ -84,19 +85,19 @@ mod depend_on_prebuilt {
8485
use super::*;
8586
use crate::import::prebuilt;
8687

87-
pub fn load_gdextension_json(_watch: &mut StopWatch) -> &'static str {
88+
pub fn load_gdextension_json(_watch: &mut StopWatch) -> std::borrow::Cow<'static, str> {
8889
prebuilt::load_gdextension_json()
8990
}
9091

9192
pub fn write_gdextension_headers(h_path: &Path, rs_path: &Path, watch: &mut StopWatch) {
9293
// Note: prebuilt artifacts just return a static str.
9394
let h_contents = prebuilt::load_gdextension_header_h();
94-
std::fs::write(h_path, h_contents)
95+
std::fs::write(h_path, h_contents.as_ref())
9596
.unwrap_or_else(|e| panic!("failed to write gdextension_interface.h: {e}"));
9697
watch.record("write_header_h");
9798

9899
let rs_contents = prebuilt::load_gdextension_header_rs();
99-
std::fs::write(rs_path, rs_contents)
100+
std::fs::write(rs_path, rs_contents.as_ref())
100101
.unwrap_or_else(|e| panic!("failed to write gdextension_interface.rs: {e}"));
101102
watch.record("write_header_rs");
102103
}

godot-codegen/src/models/json.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ pub fn load_extension_api(watch: &mut godot_bindings::StopWatch) -> JsonExtensio
262262
// #[allow]: as_ref() acts as impl AsRef<str>, but with conditional compilation
263263

264264
let json = godot_bindings::load_gdextension_json(watch);
265-
#[allow(clippy::useless_asref)]
266265
let json_str: &str = json.as_ref();
267266

268267
let model: JsonExtensionApi =

0 commit comments

Comments
 (0)