grafos_registry/
reader.rs

1//! Registry reader — read-only operations on the registry.
2
3extern crate alloc;
4use alloc::string::String;
5use alloc::vec::Vec;
6
7use grafos_std::error::Result;
8
9use crate::filter::RegistryFilter;
10use crate::region::RegistryRegion;
11use crate::registration::ServiceRegistration;
12use crate::watcher::RegistryWatcher;
13
14/// Read handle for the service registry.
15///
16/// Provides lookup, filtering, listing, and watch operations. The reader
17/// operates on a [`RegistryRegion`] which may be backed by the same leased
18/// memory as the writer (in the fabric model) or a separate region (in tests).
19pub struct RegistryReader {
20    region: RegistryRegion,
21}
22
23impl RegistryReader {
24    /// Create a reader wrapping the given region.
25    pub fn new(region: RegistryRegion) -> Self {
26        RegistryReader { region }
27    }
28
29    /// Look up all registrations for a service name.
30    pub fn lookup(&self, name: &str) -> Result<Vec<ServiceRegistration>> {
31        self.region.lookup(name)
32    }
33
34    /// Look up a single registration (first match).
35    pub fn lookup_one(&self, name: &str) -> Result<Option<ServiceRegistration>> {
36        self.region.lookup_one(name)
37    }
38
39    /// Look up registrations matching a filter.
40    pub fn lookup_filtered(
41        &self,
42        name: &str,
43        filter: &RegistryFilter,
44    ) -> Result<Vec<ServiceRegistration>> {
45        self.region.lookup_filtered(name, filter)
46    }
47
48    /// List all distinct service names.
49    pub fn list_services(&self) -> Result<Vec<String>> {
50        self.region.list_services()
51    }
52
53    /// Create a watcher anchored at the current version.
54    pub fn watch(&self) -> RegistryWatcher {
55        RegistryWatcher::new(self.region.version())
56    }
57
58    /// Return the current registry version.
59    pub fn version(&self) -> u64 {
60        self.region.version()
61    }
62}