pub struct IpcRouter {
connections: RwLock<Vec<ConnectionContext>>,
network_service: Option<Arc<dyn NetworkService>>,
process_service: Option<Arc<dyn ProcessService>>,
rate_limiter: Mutex<HashMap<RateKey, TokenBucket>>,
}Expand description
A simple in-memory router that registers connections, authorizes requests, and returns a canned ‘not implemented’ response for authorized calls.
Fields§
§connections: RwLock<Vec<ConnectionContext>>§network_service: Option<Arc<dyn NetworkService>>§process_service: Option<Arc<dyn ProcessService>>§rate_limiter: Mutex<HashMap<RateKey, TokenBucket>>Implementations§
Source§impl IpcRouter
impl IpcRouter
Sourcepub fn with_process_service(self, svc: Arc<dyn ProcessService>) -> Self
pub fn with_process_service(self, svc: Arc<dyn ProcessService>) -> Self
Set the process service.
Sourcepub fn with_network_service(self, svc: Arc<dyn NetworkService>) -> Self
pub fn with_network_service(self, svc: Arc<dyn NetworkService>) -> Self
Set the network service (thin adapter).
fn should_rate_limit(service: &str) -> bool
fn match_quotas( ctx: &ConnectionContext, method: &MethodId, ) -> Result<Option<QuotaSet>, RpcError>
async fn enforce_rate_limits( &self, ctx: &ConnectionContext, method: &MethodId, request_bytes: usize, ) -> Result<(), RpcError>
fn decode_shutdown_request( args: Vec<u8>, ) -> Result<ShutdownTreeRequest, RpcError>
Sourcefn error_response(id: u64, code: &str, message: &str) -> Response
fn error_response(id: u64, code: &str, message: &str) -> Response
Helper to create an error response.
Sourcefn success_response(id: u64, bytes: Vec<u8>) -> Response
fn success_response(id: u64, bytes: Vec<u8>) -> Response
Helper to create a success response with serialized bytes.
Sourcefn check_service<T>(
&self,
service: &Option<T>,
service_name: &str,
id: u64,
) -> Result<(), Response>
fn check_service<T>( &self, service: &Option<T>, service_name: &str, id: u64, ) -> Result<(), Response>
Helper to check if a service is configured.
Sourcefn decode_request<T: DeserializeOwned>(
&self,
args: &[u8],
method: &str,
id: u64,
) -> Result<T, Response>
fn decode_request<T: DeserializeOwned>( &self, args: &[u8], method: &str, id: u64, ) -> Result<T, Response>
Helper to decode a request from bytes.
Sourceasync fn handle_service_call<T: Serialize, E: Display>(
&self,
call: impl Future<Output = Result<T, E>>,
id: u64,
) -> Result<Response, Error>
async fn handle_service_call<T: Serialize, E: Display>( &self, call: impl Future<Output = Result<T, E>>, id: u64, ) -> Result<Response, Error>
Helper to handle service call and serialize response.
async fn dispatch_process(&self, request: Request) -> Result<Response, Error>
async fn dispatch_network(&self, request: Request) -> Result<Response, Error>
Source§impl IpcRouter
impl IpcRouter
Sourcepub fn get(&self, id: &ConnectionId) -> Option<ConnectionContext>
pub fn get(&self, id: &ConnectionId) -> Option<ConnectionContext>
Retrieve a registered connection by id.
Trait Implementations§
Source§impl Router for IpcRouter
impl Router for IpcRouter
Source§fn register_connection<'life0, 'async_trait>(
&'life0 self,
ctx: ConnectionContext,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn register_connection<'life0, 'async_trait>(
&'life0 self,
ctx: ConnectionContext,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Register a new connection after handshake.
Source§fn dispatch<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 ConnectionContext,
request: Request,
) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn dispatch<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 ConnectionContext,
request: Request,
) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Resolve and dispatch a request to a target service method.
Check whether a given method is allowed by a connection’s capabilities.
Source§fn emit_event<'life0, 'async_trait>(
&'life0 self,
event: Event,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn emit_event<'life0, 'async_trait>(
&'life0 self,
event: Event,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn observe_cancel<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 ConnectionContext,
_id: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn observe_cancel<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 ConnectionContext,
_id: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl !Freeze for IpcRouter
impl !RefUnwindSafe for IpcRouter
impl Send for IpcRouter
impl Sync for IpcRouter
impl Unpin for IpcRouter
impl !UnwindSafe for IpcRouter
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, U> ExactFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> ExactFrom<T> for Uwhere
U: TryFrom<T>,
fn exact_from(value: T) -> U
§impl<T, U> ExactInto<U> for Twhere
U: ExactFrom<T>,
impl<T, U> ExactInto<U> for Twhere
U: ExactFrom<T>,
fn exact_into(self) -> U
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
fn overflowing_into(self) -> (U, bool)
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);