From 4b2c15f0b9c82b8a2e52dd656cb0cd425f86ba18 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Thu, 18 Jul 2019 20:57:51 -0600
Subject: [PATCH] Remove scheme by ID

---
 src/scheme/mod.rs | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/scheme/mod.rs b/src/scheme/mod.rs
index da5f5cd7..83becb8f 100644
--- a/src/scheme/mod.rs
+++ b/src/scheme/mod.rs
@@ -9,6 +9,7 @@
 use alloc::sync::Arc;
 use alloc::boxed::Box;
 use alloc::collections::BTreeMap;
+use alloc::vec::Vec;
 use core::sync::atomic::AtomicUsize;
 use spin::{Once, RwLock, RwLockReadGuard, RwLockWriteGuard};
 
@@ -234,6 +235,22 @@ impl SchemeList {
         }
         Ok(id)
     }
+
+    /// Remove a scheme
+    pub fn remove(&mut self, id: SchemeId) {
+        assert!(self.map.remove(&id).is_some());
+        for (_ns, names) in self.names.iter_mut() {
+            let mut remove = Vec::with_capacity(1);
+            for (name, name_id) in names.iter() {
+                if name_id == &id {
+                    remove.push(name.clone());
+                }
+            }
+            for name in remove {
+                assert!(names.remove(&name).is_some());
+            }
+        }
+    }
 }
 
 /// Schemes list
-- 
GitLab