Skip to main content

save_to_disk

Function save_to_disk 

Source
pub fn save_to_disk(index: &OfficialIndex, path: &Path) -> Result<()>
Expand description

What: Persist an official package index to a JSON file on disk.

Inputs:

  • index: The index to serialize and write.
  • path: File path to write the JSON index to.

Output:

  • Returns Ok(()) on success.
  • Returns Err(ArchToolkitError::Io) if the directory or file cannot be written.
  • Returns Err(ArchToolkitError::Json) if serialization fails.

Details:

  • Creates the parent directory if it does not exist.
  • The derived name_to_idx field is skipped during serialization; it is rebuilt on load via load_from_disk().
  • Logs a warning when saving an empty index, since that usually indicates the index was never populated.

§Errors

Returns an error if the parent directory cannot be created, serialization fails, or the file cannot be written.

§Example

use arch_toolkit::index::{save_to_disk, OfficialIndex};
use std::path::Path;

let index = OfficialIndex::default();
save_to_disk(&index, Path::new("official_index.json"))?;