pub struct Response {
pub status: StatusCode,
pub meta: String,
pub data: Vec<u8>,
}Expand description
A Gemini response.
A Gemini response consists of two parts: The header and the content. The header is separated by a new line (CRLF or just LF) and contains two parts in itself, the status code, and a META string with more info about the status code.
§Creating a Response Struct
There are a few ways you can construct a Response struct. You can create it from its raw parts
(since all its fields are public), or you can create it using the TryFrom implementation (see
the TryFrom implementation).
Fields§
§status: StatusCodeThe status code of the response header.
meta: StringThe META string of the response header.
data: Vec<u8>The data returned from the header.
Trait Implementations§
impl Eq for Response
impl StructuralPartialEq for Response
Source§impl TryFrom<&[u8]> for Response
impl TryFrom<&[u8]> for Response
Source§fn try_from(raw_response: &[u8]) -> Result<Self, ResponseParseError>
fn try_from(raw_response: &[u8]) -> Result<Self, ResponseParseError>
Parses a response from a u8 slice.
§Arguments:
raw_response- The raw response bytes to parse
§Returns:
- A Result with either a fully parsed response or an error describing what went wrong when parsing
§Example:
use std::convert::TryFrom;
let raw_response = r#"20 text/gemini
# Test response
Hello!"#;
let res = Response::try_from(raw_response.as_bytes()).unwrap();
assert_eq!(res.status, StatusCode::Success(0));
assert_eq!(res.meta, "text/gemini");
assert_eq!(String::from_utf8_lossy(&res.data).into_owned(), "# Test response\nHello!");
}Source§type Error = ResponseParseError
type Error = ResponseParseError
The type returned in the event of a conversion error.
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnsafeUnpin for Response
impl UnwindSafe for Response
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