pub struct Registry {
pub entries: HashMap<String, RegistryEntry>,
}Expand description
In-memory known-good registry. Cheap to clone (entries live in a
HashMap, keys are short ASCII names).
Fields§
§entries: HashMap<String, RegistryEntry>All entries keyed by name for O(1) exact-match lookup.
Implementations§
Source§impl Registry
impl Registry
Sourcepub fn builtin() -> Self
pub fn builtin() -> Self
Hardcoded fallback list — well-known modelcontextprotocol/servers
entries. Always succeeds, never touches the network or filesystem.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of entries. Convenience for callers that want a one-line “registry has N known-good entries” message.
Sourcepub fn get(&self, name: &str) -> Option<&RegistryEntry>
pub fn get(&self, name: &str) -> Option<&RegistryEntry>
Look up an exact name match.
Sourcepub fn closest(&self, name: &str, max: usize) -> Option<(&RegistryEntry, usize)>
pub fn closest(&self, name: &str, max: usize) -> Option<(&RegistryEntry, usize)>
Find the closest entry to name by Levenshtein distance, returning
Some((entry, distance)) only when the distance is in 1..=max
(zero would be an exact match — not a typosquat).
Sourcepub async fn fetch(url: &str) -> Result<Self>
pub async fn fetch(url: &str) -> Result<Self>
Fetch the registry from a JSON endpoint serving a
[{"name":..., "source":...}, ...] array.
§Errors
crate::Error::Httpon network / TLS / non-2xx response.crate::Error::Jsonon payload shape mismatch.
Sourcepub fn from_entries(entries: Vec<RegistryEntry>) -> Self
pub fn from_entries(entries: Vec<RegistryEntry>) -> Self
Build a registry from an arbitrary entries list. Useful for tests and for parsing locally-managed allowlists.
Sourcepub fn cache_path(paths: &Paths) -> PathBuf
pub fn cache_path(paths: &Paths) -> PathBuf
Path of the local cache file under Paths::home.
Sourcepub fn load_cached(paths: &Paths) -> Result<Option<Self>>
pub fn load_cached(paths: &Paths) -> Result<Option<Self>>
Load the cached registry if Self::cache_path exists, else
Ok(None).
§Errors
crate::Error::Ioon read failure.crate::Error::Jsonon parse failure.
Sourcepub fn save_cached(&self, paths: &Paths) -> Result<PathBuf>
pub fn save_cached(&self, paths: &Paths) -> Result<PathBuf>
Persist self to Self::cache_path.
§Errors
crate::Error::Ioon dir / file write failure.crate::Error::Jsonon serialization failure.
Sourcepub fn load_or_builtin(paths: &Paths) -> Self
pub fn load_or_builtin(paths: &Paths) -> Self
Resolve a registry through the source chain documented at the
module level: cache → builtin. Network fetch is not triggered
here — callers that want a fresh pull should call
Self::fetch explicitly and then Self::save_cached.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Registry
impl<'de> Deserialize<'de> for Registry
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Registry
impl RefUnwindSafe for Registry
impl Send for Registry
impl Sync for Registry
impl Unpin for Registry
impl UnsafeUnpin for Registry
impl UnwindSafe for Registry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more