mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-22 05:52:23 -05:00
Use a custom capacity for the JSON buffer
This commit is contained in:
parent
9c6f56b836
commit
b3aef377be
1 changed files with 6 additions and 4 deletions
|
@ -31,10 +31,12 @@ impl RustAnalyzerProject {
|
||||||
|
|
||||||
/// Write rust-project.json to disk
|
/// Write rust-project.json to disk
|
||||||
pub fn write_to_disk(&self) -> Result<(), std::io::Error> {
|
pub fn write_to_disk(&self) -> Result<(), std::io::Error> {
|
||||||
std::fs::write(
|
// Using the capacity 2^14 = 16384 since the file length in bytes is higher than 2^13.
|
||||||
"./rust-project.json",
|
// The final length is not known exactly because it depends on the user's sysroot path,
|
||||||
serde_json::to_vec(&self).expect("Failed to serialize to JSON"),
|
// the current number of exercises etc.
|
||||||
)?;
|
let mut buf = Vec::with_capacity(16384);
|
||||||
|
serde_json::to_writer(&mut buf, &self).expect("Failed to serialize to JSON");
|
||||||
|
std::fs::write("rust-project.json", buf)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue