Platform cache root. Returns `None` when the host has no usable cache directory (wasm) or when the env vars used to derive the path aren't set. Resolution order: - macOS / iOS / tvOS / watchOS: `$HOME/Library/Caches/bloom/sdf` - Linux / Android: `${XDG_CACHE_HOME:-$HOME/.cache}/bloom/sdf` - Windows: `%LOCALAPPDATA%\bloom\cache\sdf` - wasm32:
()
| 107 | /// - Windows: `%LOCALAPPDATA%\bloom\cache\sdf` |
| 108 | /// - wasm32: `None` |
| 109 | pub fn cache_dir() -> Option<PathBuf> { |
| 110 | #[cfg(target_arch = "wasm32")] |
| 111 | { return None; } |
| 112 | |
| 113 | #[cfg(not(target_arch = "wasm32"))] |
| 114 | { |
| 115 | let dir = if cfg!(target_vendor = "apple") { |
| 116 | let home = std::env::var_os("HOME")?; |
| 117 | PathBuf::from(home).join("Library").join("Caches").join("bloom").join("sdf") |
| 118 | } else if cfg!(target_os = "windows") { |
| 119 | let local = std::env::var_os("LOCALAPPDATA")?; |
| 120 | PathBuf::from(local).join("bloom").join("cache").join("sdf") |
| 121 | } else { |
| 122 | // Linux + Android (XDG-style). |
| 123 | let base = std::env::var_os("XDG_CACHE_HOME") |
| 124 | .map(PathBuf::from) |
| 125 | .or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".cache")))?; |
| 126 | base.join("bloom").join("sdf") |
| 127 | }; |
| 128 | Some(dir) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | /// Resolve a hash to its cache file path, creating the cache root if |
| 133 | /// needed. Returns `None` if the cache dir can't be created. |
no outgoing calls