CommandRequest

Struct CommandRequest 

Source
pub struct CommandRequest {
    pub headers: Vec<(String, String)>,
    pub body: Option<Vec<u8>>,
    pub content_type: Option<String>,
    pub content_schema: Option<String>,
}
Expand description

A command request to execute a state change.

Fields§

§headers: Vec<(String, String)>

HTTP-style headers for the request.

§body: Option<Vec<u8>>

Optional request body.

§content_type: Option<String>

Content type of the body (e.g., “application/json”).

§content_schema: Option<String>

Optional content schema URL for validation.

Implementations§

Source§

impl CommandRequest

Source

pub fn new() -> CommandRequest

Create a new empty command request.

Source

pub fn with_body(body: Vec<u8>) -> CommandRequest

Create a command request with a body.

Source

pub fn json<T>(value: &T) -> Result<CommandRequest, CommandRequestError>
where T: Serialize,

Create a command request with a JSON-serialized body.

This serializes the value to JSON and sets the appropriate Content-Type header.

§Example
use evidentsource_core::domain::CommandRequest;
use serde::Serialize;

#[derive(Serialize)]
struct CreateAccount {
    account_id: String,
    initial_balance: u64,
}

let cmd = CreateAccount {
    account_id: "acc-123".to_string(),
    initial_balance: 1000,
};

let request = CommandRequest::json(&cmd).unwrap();
assert_eq!(request.get_header("Content-Type"), Some("application/json"));
Source

pub fn header( self, name: impl Into<String>, value: impl Into<String>, ) -> CommandRequest

Add a header to the request.

Source

pub fn body(self, body: Vec<u8>) -> CommandRequest

Set the request body.

Source

pub fn content_type(self, content_type: impl Into<String>) -> CommandRequest

Set the content type.

§Example
use evidentsource_core::domain::CommandRequest;

let request = CommandRequest::new()
    .body(b"<xml>data</xml>".to_vec())
    .content_type("application/xml");
Source

pub fn content_schema(self, schema_url: impl Into<String>) -> CommandRequest

Set the content schema URL.

§Example
use evidentsource_core::domain::CommandRequest;

let request = CommandRequest::new()
    .body(b"{}".to_vec())
    .content_type("application/json")
    .content_schema("https://example.com/schemas/command.json");
Source

pub fn get_header(&self, name: &str) -> Option<&str>

Get a header value by name.

Trait Implementations§

Source§

impl Clone for CommandRequest

Source§

fn clone(&self) -> CommandRequest

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CommandRequest

Source§

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

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

impl Default for CommandRequest

Source§

fn default() -> CommandRequest

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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