Detaches an existing drive named `name`. The drive `name` must exist, cannot be the current drive, and cannot be the last mounted drive.
(&mut self, name: &str)
| 477 | /// The drive `name` must exist, cannot be the current drive, and cannot be the last mounted |
| 478 | /// drive. |
| 479 | pub fn unmount(&mut self, name: &str) -> io::Result<()> { |
| 480 | let key = DriveKey::new(name)?; |
| 481 | if !self.drives.contains_key(&key) { |
| 482 | return Err(io::Error::new( |
| 483 | io::ErrorKind::NotFound, |
| 484 | format!("Drive '{}' is not mounted", name), |
| 485 | )); |
| 486 | } |
| 487 | if self.current == key { |
| 488 | return Err(io::Error::new( |
| 489 | io::ErrorKind::AlreadyExists, |
| 490 | format!("Cannot unmount the current drive '{}'", name), |
| 491 | )); |
| 492 | } |
| 493 | assert!( |
| 494 | self.drives.len() > 1, |
| 495 | "There must be more than one drive if the current drive is not the given name" |
| 496 | ); |
| 497 | self.drives.remove(&key).expect("Drive presence in map checked above"); |
| 498 | Ok(()) |
| 499 | } |
| 500 | |
| 501 | /// Returns information about the mounted drives as a mapping of drive names to the URIs that |
| 502 | /// were used to mount them. |