Skip to content

Commit d2d191d

Browse files
authored
Merge pull request #1349 from Yarwin/add-polyfill-for-read-as-gstring-entire
Support `read_as_gstring_entire` in Godot versions newer than 4.5.
2 parents 8f47818 + 94df0b8 commit d2d191d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

godot-core/src/tools/gfile.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,30 @@ impl GFile {
332332
///
333333
/// Underlying Godot method:
334334
/// [`FileAccess::get_as_text`](https://docs.godotengine.org/en/stable/classes/class_fileaccess.html#class-fileaccess-method-get-as-text).
335+
// For Godot versions before `skip_cr` has been removed, see: https://github.com/godotengine/godot/pull/110867.
335336
#[doc(alias = "get_as_text")]
337+
#[cfg(before_api = "4.6")]
336338
pub fn read_as_gstring_entire(&mut self, skip_cr: bool) -> std::io::Result<GString> {
337339
let val = self.fa.get_as_text_ex().skip_cr(skip_cr).done();
338340
self.check_error()?;
339341
Ok(val)
340342
}
341343

344+
/// Reads the whole file as UTF-8 [`GString`].
345+
///
346+
/// To retrieve the file as [`String`] instead, use the [`Read`] trait method
347+
/// [`read_to_string()`](https://doc.rust-lang.org/std/io/trait.Read.html#method.read_to_string).
348+
///
349+
/// Underlying Godot method:
350+
/// [`FileAccess::get_as_text`](https://docs.godotengine.org/en/stable/classes/class_fileaccess.html#class-fileaccess-method-get-as-text).
351+
#[doc(alias = "get_as_text")]
352+
#[cfg(since_api = "4.6")]
353+
pub fn read_as_gstring_entire(&mut self) -> std::io::Result<GString> {
354+
let val = self.fa.get_as_text();
355+
self.check_error()?;
356+
Ok(val)
357+
}
358+
342359
/// Reads the next line of the file in delimiter-separated file.
343360
///
344361
/// For reading traditional `CSV` format, provide comma (`','`) as `delim`.

0 commit comments

Comments
 (0)