Struct RouterClient
pub struct RouterClient { /* private fields */ }Expand description
A client that can be composed from multiple subclients to interact with all of them as one.
§Bot IDs
BotIds are prefixed with the key used to insert the subclient. Take that into account when
calling send or when reading the list of bots from bots.
If you are just forwarding an id that came from bots, to the send
method, you don’t need to worry.
If you are creating BotIds manually you can use RouterClient::prefix and RouterClient::unprefix
methods to help you.
§Cache
This router works by caching the results from calling bots on each sub-client.
The method will only be called for a specific sub-client if there is no cached result yet, or if
the cached result contains errors.
If a client is associated with a cached result, without errors, then its bots method
will not be called again.
If you need to refresh the list of bots, you will need to invalidate the cache explicitly.
Implementations§
§impl RouterClient
impl RouterClient
pub fn new() -> RouterClient
pub fn invalidate_all_bots_cache(&self)
pub fn invalidate_all_bots_cache(&self)
Invalidates the bots cache for all sub-clients.
pub fn invalidate_bots_cache(&self, key: impl AsRef<str>)
pub fn invalidate_bots_cache(&self, key: impl AsRef<str>)
Invalidates the bots cache for the client with the given key.
pub fn insert_client(&self, key: impl AsRef<str>, client: Box<dyn BotClient>)
pub fn insert_client(&self, key: impl AsRef<str>, client: Box<dyn BotClient>)
Inserts a client with the given key.
pub fn remove_client(&self, key: impl AsRef<str>)
pub fn remove_client(&self, key: impl AsRef<str>)
Removes a client by the key used to insert it.
pub fn get_client_cloned(
&self,
key: impl AsRef<str>,
) -> Option<Box<dyn BotClient>>
pub fn get_client_cloned( &self, key: impl AsRef<str>, ) -> Option<Box<dyn BotClient>>
Gets a client by the key used to insert it, cloning it.
pub fn read_client<F, R>(&self, key: impl AsRef<str>, f: F) -> Option<R>
pub fn read_client<F, R>(&self, key: impl AsRef<str>, f: F) -> Option<R>
Access a client immutably by the key used to insert it.
The closure will not be called if there is no client for the given key,
but this function will give None in that case.
pub fn write_client<F, R>(&self, key: impl AsRef<str>, f: F) -> Option<R>
pub fn write_client<F, R>(&self, key: impl AsRef<str>, f: F) -> Option<R>
Access a client mutably by the key used to insert it.
The closure will not be called if there is no client for the given key,
but this function will give None in that case.
Trait Implementations§
§impl BotClient for RouterClient
impl BotClient for RouterClient
§fn bots(
&mut self,
) -> Pin<Box<dyn PlatformSendFuture<Output = ClientResult<Vec<Bot>>>>>
fn bots( &mut self, ) -> Pin<Box<dyn PlatformSendFuture<Output = ClientResult<Vec<Bot>>>>>
§fn send(
&mut self,
bot_id: &BotId,
messages: &[Message],
tools: &[Tool],
) -> Pin<Box<dyn PlatformSendStream<Item = ClientResult<MessageContent>>>>
fn send( &mut self, bot_id: &BotId, messages: &[Message], tools: &[Tool], ) -> Pin<Box<dyn PlatformSendStream<Item = ClientResult<MessageContent>>>>
§impl Clone for RouterClient
impl Clone for RouterClient
§fn clone(&self) -> RouterClient
fn clone(&self) -> RouterClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Default for RouterClient
impl Default for RouterClient
§fn default() -> RouterClient
fn default() -> RouterClient
Auto Trait Implementations§
impl Freeze for RouterClient
impl RefUnwindSafe for RouterClient
impl Send for RouterClient
impl Sync for RouterClient
impl Unpin for RouterClient
impl UnwindSafe for RouterClient
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.