Skip to main content

Request

Struct Request 

Source
pub struct Request {
    pub id: RequestId,
    pub category: EventCategory,
    pub operation: String,
    pub source: ComponentId,
    pub target: Option<ComponentId>,
    pub channel: ChannelId,
    pub payload: Value,
    pub timeout_ms: u64,
}
Expand description

A synchronous request message between Components.

Represents a query that expects exactly one Response.

§Required Fields

All fields except target are mandatory and have no sensible defaults:

FieldWhy No Default
idMust be unique per request (generated by Request::new)
operationDefines what action to perform
sourceIdentifies the requesting Component
channelExecution context for permission/scope
payloadOperation-specific data
timeout_msHas default, but requires explicit construction

§Why No Default Implementation

DO NOT implement Default for this type.

Reasons:

  1. id must be unique: Each request needs a fresh RequestId. A Default impl would either reuse the same ID (broken) or generate new ones (hidden side effect in Default).

  2. source is mandatory: There is no “anonymous” request. Every request must have an identifiable source for routing and permission checking.

  3. channel is mandatory: Requests without a channel cannot be scoped for permission inheritance or signal targeting.

  4. operation is mandatory: An empty operation string is meaningless and would fail at runtime.

§Serde Deserialization

When deserializing, all fields must be present in the input. There are no #[serde(default)] attributes intentionally. Partial requests are rejected at deserialization time.

§Example

use orcs_event::{Request, EventCategory};
use orcs_types::{ComponentId, ChannelId};
use serde_json::json;

let request = Request::new(
    EventCategory::Echo,
    "read",
    ComponentId::builtin("tool"),
    ChannelId::new(),
    json!({ "path": "/tmp/file.txt" }),
);

assert_eq!(request.operation, "read");
assert!(request.target.is_none());

Fields§

§id: RequestId

Unique identifier for this request.

Generated automatically by Request::new. Used to correlate with the corresponding Response.

§category: EventCategory

Event category for subscription-based routing.

The EventBus routes this request only to Components that subscribe to this category.

§operation: String

Operation name (e.g., “chat”, “read”, “approve”).

Determines how the target Component processes the request.

§source: ComponentId

Source Component that initiated this request.

Used for:

  • Response routing
  • Permission checking
  • Audit logging
§target: Option<ComponentId>

Target Component (optional).

  • Some(id): Direct request to specific Component
  • None: Broadcast to all Components handling this operation
§channel: ChannelId

Execution context channel.

Used for:

  • Permission scope inheritance
  • Signal targeting (cancel, pause, etc.)
  • Parallel execution isolation
§payload: Value

Operation-specific payload.

Structure depends on the operation type.

§timeout_ms: u64

Timeout in milliseconds.

Default: DEFAULT_TIMEOUT_MS (30 seconds). Override with Request::with_timeout.

Implementations§

Source§

impl Request

Source

pub fn new( category: EventCategory, operation: impl Into<String>, source: ComponentId, channel: ChannelId, payload: Value, ) -> Request

Creates a new Request with a unique ID and default timeout.

Note: This method does not validate the operation string. For validated construction, use Request::try_new via the TryNew trait.

§Arguments
  • category - Event category for routing
  • operation - Operation name (e.g., “chat”, “read”)
  • source - The Component initiating this request
  • channel - Execution context for scoping
  • payload - Operation-specific data
§Example
use orcs_event::{Request, EventCategory};
use orcs_types::{ComponentId, ChannelId};
use serde_json::json;

let req = Request::new(
    EventCategory::Echo,
    "echo",
    ComponentId::builtin("test"),
    ChannelId::new(),
    json!({ "message": "Hello" }),
);
Source

pub fn with_target(self, target: ComponentId) -> Request

Sets the target Component for direct routing.

By default, requests are broadcast to all Components that handle the operation. Use this to send directly to one.

§Example
use orcs_event::{Request, EventCategory};
use orcs_types::{ComponentId, ChannelId};
use serde_json::Value;

let req = Request::new(
    EventCategory::Hil,
    "approve",
    ComponentId::builtin("tool"),
    ChannelId::new(),
    Value::Null,
)
.with_target(ComponentId::builtin("hil"));

assert!(req.target.is_some());
Source

pub fn with_timeout(self, timeout_ms: u64) -> Request

Sets a custom timeout in milliseconds.

Default is DEFAULT_TIMEOUT_MS (30 seconds).

§Example
use orcs_event::{Request, EventCategory};
use orcs_types::{ComponentId, ChannelId};
use serde_json::Value;

// Short timeout for quick operations
let req = Request::new(
    EventCategory::Lifecycle,
    "ping",
    ComponentId::builtin("monitor"),
    ChannelId::new(),
    Value::Null,
)
.with_timeout(1000);  // 1 second

assert_eq!(req.timeout_ms, 1000);

Trait Implementations§

Source§

impl Clone for Request

Source§

fn clone(&self) -> Request

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Request

Source§

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

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

impl<'de> Deserialize<'de> for Request

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Request, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Request

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryNew for Request

Source§

fn try_new( args: <Request as TryNew>::Args, ) -> Result<Request, <Request as TryNew>::Error>

Attempts to create a new Request with validation.

§Validation
  • operation must not be empty
  • operation must not be whitespace-only
§Errors

Returns EventError::InvalidRequest if validation fails.

§Example
use orcs_event::{Request, RequestArgs, EventError, EventCategory};
use orcs_types::{ComponentId, ChannelId, TryNew, ErrorCode};
use serde_json::Value;

// Valid request
let args = RequestArgs {
    category: EventCategory::Echo,
    operation: "echo".to_string(),
    source: ComponentId::builtin("echo"),
    channel: ChannelId::new(),
    payload: Value::Null,
};
assert!(Request::try_new(args).is_ok());

// Invalid: empty operation
let args = RequestArgs {
    category: EventCategory::Echo,
    operation: String::new(),
    source: ComponentId::builtin("echo"),
    channel: ChannelId::new(),
    payload: Value::Null,
};
let err = Request::try_new(args).unwrap_err();
assert_eq!(err.code(), "EVENT_INVALID_REQUEST");
Source§

type Error = EventError

The error type returned when construction fails. Read more
Source§

type Args = RequestArgs

Arguments required for construction. 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T
where T: Send,

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> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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