From 0dec882e88a84e487526e3f6c29dc8b4df208b1f Mon Sep 17 00:00:00 2001 From: Alexander Koz Date: Fri, 27 Oct 2023 13:20:39 +0400 Subject: [PATCH] fs: little improvement - buf prefill & doc --- Cargo.lock | 2 +- api/fs/Cargo.toml | 2 +- api/fs/src/lib.rs | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7594174b..4133ae5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2557,7 +2557,7 @@ dependencies = [ [[package]] name = "playdate-fs" -version = "0.2.5" +version = "0.2.6" dependencies = [ "playdate-sys", "playdate-system", diff --git a/api/fs/Cargo.toml b/api/fs/Cargo.toml index 0f71f1bb..df915543 100644 --- a/api/fs/Cargo.toml +++ b/api/fs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-fs" -version = "0.2.5" +version = "0.2.6" readme = "README.md" description = "High-level file-system API built on-top of Playdate API" keywords = ["playdate", "sdk", "api", "gamedev"] diff --git a/api/fs/src/lib.rs b/api/fs/src/lib.rs index 215f6f5b..8dfdac81 100644 --- a/api/fs/src/lib.rs +++ b/api/fs/src/lib.rs @@ -48,8 +48,7 @@ pub fn read>(path: P, data_dir: bool) -> Result, ApiError let size = fs.metadata(path).map(|m| m.size).ok().unwrap_or(0); // prepare prefilled buffer: - let mut buf = Vec::::with_capacity(size as usize); - buf.resize(size as usize, 0); + let mut buf = alloc::vec![0; size as usize]; fs.read(&mut file, &mut buf, size)?; Ok(buf) @@ -318,8 +317,8 @@ impl Fs { /// /// Caution: Vector must be prefilled with `0`s. /// ```no_run - /// let mut buf = Vec::::with_capacity(size as usize); - /// buf.resize(size as usize, 0); + /// let mut buf = Vec::::with_capacity(size); + /// buf.resize(size, 0); /// fs.read(&mut file, &mut buf, size)?; /// ``` ///