Skip to main content

RegistryStore

Struct RegistryStore 

Source
pub struct RegistryStore { /* private fields */ }
Expand description

The live set, and the only way to change it.

§Examples

use protocol_droid::domain::registry::{Primitive, PrimitiveKind, Tool};
use protocol_droid::application::registry::RegistryStore;

let store = RegistryStore::new();
assert!(store.snapshot().is_blank());

let published = store.register(Primitive::from(
    Tool::new("echo", r#"{"type":"object"}"#)?,
));

assert_eq!(published.changed(), [PrimitiveKind::Tool]);
assert_eq!(store.snapshot().len(PrimitiveKind::Tool), 1);

Implementations§

Source§

impl RegistryStore

Source

pub fn list_visible( &self, session: &AuthContext, profile: &FeatureProfile, kind: PrimitiveKind, ) -> Listing

Every primitive of kind that session may see.

Takes an owned Arc<Snapshot> rather than a guard, so a caller that goes on to build a response, or hand the primitives to a tool, is not holding the store against a publish for the duration.

Source

pub fn get_visible( &self, session: &AuthContext, profile: &FeatureProfile, kind: PrimitiveKind, id: &str, ) -> Option<Arc<Registered>>

One primitive, if session may see it.

A miss is None whether the primitive is absent or merely hidden, and that is deliberate: telling a caller which would let a session probe for the existence of a tool it cannot see by reading the difference between a 404 and a 403. The server still logs the difference.

Source§

impl RegistryStore

Source

pub fn new() -> Self

An empty store at generation zero.

Source

pub fn with(snapshot: Snapshot) -> Self

A store seeded with a snapshot, at that snapshot’s generation.

Source

pub fn snapshot(&self) -> Arc<Snapshot> ⓘ

The current snapshot, owned.

An Arc clone, not a borrow. The caller may hold it for as long as it likes — across a publish, across a long-running tool — and no publish waits on it.

Source

pub fn generation(&self) -> u64

The current publish number.

Source

pub fn register(&self, primitive: impl Into<Registered>) -> Published

Adds a primitive, replacing any primitive already filed under its id.

A replacement is one publish and one generation, not a removal followed by an add: a subscriber that hears about it twice has been told the tool went away and came back, which is a lie that costs a re-list.

The primitive is captured behind an Arc because Self::publish may run its closure more than once, and a retry must be able to install the same primitive without taking the first attempt’s copy of it. The alternative is a clone per attempt, which on a contended registry means deep-copying a tool’s schema on every retry.

Source

pub fn unregister(&self, kind: PrimitiveKind, id: &PrimitiveId) -> Published

Takes a primitive out of the set.

Removing something that is not there is not an error: the observable state afterwards is the same either way, and a caller tearing down a tool it may never have registered should not have to check first. The returned Published reports is_noop, so a notification is still suppressed.

Source

pub fn apply( &self, primitives: impl IntoIterator<Item = Registered>, ) -> Published

Publishes several changes as one generation.

A batch is one publish rather than a sequence of them so that a subscriber told about the result never observes a half-applied set. That is the only reason this takes a slice: the alternative is a caller looping over Self::register, and a reader racing the loop sees generation N with the first change and N+2 with the last.

Trait Implementations§

Source§

impl Debug for RegistryStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RegistryStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more