Struct Reply

Source
pub struct Reply { /* private fields */ }
Expand description

A successful response with JSON data to be sent back to the client.

There are two kinds of replies. Static replies represent JSON data that is ready. Most requests return static replies. Streaming replies represent a stream of JSON data that will stream from a Channel directly to the client. You can’t access the data of a streaming reply through the Reply struct, since it’s not ready yet. If you want to transform or edit the reply data for a stream, you’ll need to implement a custom Channel instead.

These are several ways to create a Reply:

  • pass a Request to an Adapter to get a static response from a database
  • pass a Request to a Channel to get a streaming response
  • in your custom Resource, call request.into_reply(data) to create a Reply object.

Reply implements IntoFuture, so you can return it directly from a and_then block.

Implementations§

Source§

impl Reply

Source

pub fn data(&self) -> Option<&JsonObject>

Source

pub fn data_mut(&mut self) -> Option<&mut JsonObject>

Examples found in repository?
examples/4.rs (line 14)
8fn main() {
9  let mut server = Server::new();
10  let database = memory::MemoryAdapter::new();
11  server.resource("/cats", move |req: Request| {
12    database.handle(req).and_then(|mut reply| {
13      {
14          let mut data = reply.data_mut().unwrap();
15          data.insert("example".to_string(), json!("data"));
16      }
17      reply
18    })
19  });
20  server.listen("127.0.0.1:3000");
21}
Source

pub fn to_http(self) -> Response<Body>

Source

pub fn method(&self) -> Method

Source

pub fn resource(&self) -> &str

Source

pub fn id(&self) -> &Option<String>

Source

pub fn params(&self) -> &JsonObject

Source

pub fn param(&self, key: &str) -> &JsonValue

Source

pub fn boxed(self) -> BoxFuture<Reply, Error>

Source

pub fn request_data(&self) -> &JsonObject

Trait Implementations§

Source§

impl Debug for Reply

Source§

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

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

impl IntoFuture for Reply

Source§

type Item = Reply

The item that the future may resolve with.
Source§

type Error = Error

The error that the future may resolve with.
Source§

type Future = FutureResult<Reply, Error>

The future that this type can be converted into.
Source§

fn into_future(self) -> Self::Future

Consumes this object and produces a future.

Auto Trait Implementations§

§

impl Freeze for Reply

§

impl !RefUnwindSafe for Reply

§

impl Send for Reply

§

impl !Sync for Reply

§

impl Unpin for Reply

§

impl !UnwindSafe for Reply

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.