| 104 | } |
| 105 | |
| 106 | pub fn write_disk_cache(file_path: &Path, data: &impl Encode) -> std::io::Result<()> { |
| 107 | println!("Writing cache to {}...", file_path.display()); |
| 108 | if let Some(parent) = file_path.parent() { |
| 109 | if !parent.exists() { |
| 110 | std::fs::create_dir_all(parent)?; |
| 111 | } |
| 112 | } |
| 113 | let encoded_data = bitcode::encode(data); |
| 114 | let compressed_data = compress(&encoded_data, DEFAULT_COMPRESSION_LEVEL)?; |
| 115 | std::fs::write(file_path, compressed_data) |
| 116 | } |
| 117 | |
| 118 | pub fn read_disk_cache<T>(file_path: &Path) -> std::io::Result<T> |
| 119 | where |