pub struct ServiceCtx { /* private fields */ }Expand description
Process-aware context injected into VX endpoint handlers.
Provides access to the service’s private heap state and the Tri-Lane router for inter-service communication.
§Example
ⓘ
async fn handle(ctx: &ServiceCtx) -> Result<String, VilError> {
let db = ctx.state::<DbPool>()?;
ctx.send("analytics", b"page_view").await?;
Ok("ok".into())
}Implementations§
Source§impl ServiceCtx
impl ServiceCtx
Sourcepub fn new(
service_name: impl Into<String>,
state: Arc<dyn Any + Send + Sync>,
tri_lane: Arc<TriLaneRouter>,
) -> Self
pub fn new( service_name: impl Into<String>, state: Arc<dyn Any + Send + Sync>, tri_lane: Arc<TriLaneRouter>, ) -> Self
Create a new service context.
Sourcepub fn service_name(&self) -> &str
pub fn service_name(&self) -> &str
Get the service name.
Sourcepub fn state<T: Send + Sync + 'static>(&self) -> Result<&T, VilError>
pub fn state<T: Send + Sync + 'static>(&self) -> Result<&T, VilError>
Downcast the private heap state to a concrete type.
Returns Err if the type does not match.
Sourcepub fn state_raw(&self) -> &Arc<dyn Any + Send + Sync>
pub fn state_raw(&self) -> &Arc<dyn Any + Send + Sync>
Get a reference to the raw state Arc (for advanced usage).
Sourcepub fn tri_lane(&self) -> &Arc<TriLaneRouter>
pub fn tri_lane(&self) -> &Arc<TriLaneRouter>
Get a reference to the Tri-Lane router.
Sourcepub async fn send(&self, target: &str, data: &[u8]) -> Result<usize, VilError>
pub async fn send(&self, target: &str, data: &[u8]) -> Result<usize, VilError>
Send data to a target service via the Data Lane.
Use this for payload transfer (request/response bodies, file data).
Trait Implementations§
Source§impl Clone for ServiceCtx
impl Clone for ServiceCtx
Source§fn clone(&self) -> ServiceCtx
fn clone(&self) -> ServiceCtx
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ServiceCtx
impl Debug for ServiceCtx
Source§impl FromRequestParts<AppState> for ServiceCtx
impl FromRequestParts<AppState> for ServiceCtx
Auto Trait Implementations§
impl Freeze for ServiceCtx
impl !RefUnwindSafe for ServiceCtx
impl Send for ServiceCtx
impl Sync for ServiceCtx
impl Unpin for ServiceCtx
impl UnsafeUnpin for ServiceCtx
impl !UnwindSafe for ServiceCtx
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.