pub struct FetchResponsePending { /* private fields */ }
Expand description

FetchResponsePending is a placeholder for the HTTP server’s response. It is returned when crate::fetch::HttpFetch::send_streaming is called. It is then used to retrive FetchResponse from the server.

Example

use edjx::{HttpFetch, FetchResponse, BaseStream, Uri};
use std::str::FromStr;

let fetch_uri = Uri::from_str("https://httpbin.org/post").unwrap();
let (fet_resp_pending, mut write_stream) = HttpFetch::post(fetch_uri).send_streaming().unwrap();

write_stream.write_chunk_text("Chunk text").unwrap();
write_stream.close().unwrap();

let mut fetch_res: FetchResponse = fet_resp_pending.get_fetch_response().unwrap();

Implementations§

Examples found in repository?
src/fetch.rs (line 335)
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
    pub fn send_streaming(&self) -> Result<(FetchResponsePending, WriteStream), HttpError> {
        let headers_vec =
            serde_json::to_vec(&super::utils::convert_to_hashmap(&self.parts.headers)).unwrap();
        let headers_slice = headers_vec.as_slice();
        let version: String = super::utils::to_version_string(&self.parts.version);
        let method: String = self.parts.method.as_str().to_string();
        let uri: String = self.parts.uri.to_string();

        let mut error_code: i32 = 0;
        let mut sd: u32 = 0;

        let response_value = unsafe {
            host_fetch_send_streaming(
                version.as_ptr(),
                version.len() as u32,
                headers_slice.as_ptr(),
                headers_slice.len() as u32,
                uri.as_ptr(),
                uri.len() as u32,
                method.as_ptr(),
                method.len() as u32,
                &mut sd,
                &mut error_code,
            )
        };

        if response_value < 0 {
            return Err(HttpError::from(Error::from_i32(error_code).unwrap()));
        }

        Ok((FetchResponsePending::new(sd), BaseStream::new(sd)))
    }

This function is used to retrive FetchResponse from the remote server once the response is ready.

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.