Skip to content

Commit

Permalink
fs: little improvement - buf prefill & doc
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook committed Oct 27, 2023
1 parent ed2873f commit 0dec882
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/fs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
7 changes: 3 additions & 4 deletions api/fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ pub fn read<P: AsRef<Path>>(path: P, data_dir: bool) -> Result<Vec<u8>, ApiError
let size = fs.metadata(path).map(|m| m.size).ok().unwrap_or(0);

// prepare prefilled buffer:
let mut buf = Vec::<u8>::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)
Expand Down Expand Up @@ -318,8 +317,8 @@ impl<Api: api::Api> Fs<Api> {
///
/// Caution: Vector must be prefilled with `0`s.
/// ```no_run
/// let mut buf = Vec::<u8>::with_capacity(size as usize);
/// buf.resize(size as usize, 0);
/// let mut buf = Vec::<u8>::with_capacity(size);
/// buf.resize(size, 0);
/// fs.read(&mut file, &mut buf, size)?;
/// ```
///
Expand Down

0 comments on commit 0dec882

Please sign in to comment.