Parse remote configuration from TOML content.
(content: &str, path: &Path)
| 291 | |
| 292 | /// Parse remote configuration from TOML content. |
| 293 | fn parse(content: &str, path: &Path) -> RemoteResult<Self> { |
| 294 | // Parse the full config file as a table |
| 295 | let full_config: toml::map::Map<String, toml::Value> = |
| 296 | toml::from_str(content).map_err(|e| RemoteError::ParseError { |
| 297 | path: path.display().to_string(), |
| 298 | message: e.to_string(), |
| 299 | })?; |
| 300 | |
| 301 | // Extract the remotes section |
| 302 | let remotes = if let Some(remotes_value) = full_config.get("remotes") { |
| 303 | // Convert the Value directly to the expected type |
| 304 | remotes_value |
| 305 | .clone() |
| 306 | .try_into::<BTreeMap<String, RemoteEntry>>() |
| 307 | .map_err(|e| RemoteError::ParseError { |
| 308 | path: path.display().to_string(), |
| 309 | message: format!("invalid remotes section: {}", e), |
| 310 | })? |
| 311 | } else { |
| 312 | BTreeMap::new() |
| 313 | }; |
| 314 | |
| 315 | Ok(Self { remotes }) |
| 316 | } |
| 317 | |
| 318 | /// Save remote configuration to a config file. |
| 319 | /// |