pub struct Response {
pub id: RequestId,
pub response_type: ResponseType,
pub result: Option<Value>,
pub error: Option<String>,
pub message: Option<String>,
}Expand description
A response from remote end to local end.
§Format
Success:
{
"id": "uuid",
"type": "success",
"result": { ... }
}Error:
{
"id": "uuid",
"type": "error",
"error": "error code",
"message": "error message"
}Fields§
§id: RequestIdMatches the command id.
response_type: ResponseTypeResponse type.
result: Option<Value>Result data (if success).
error: Option<String>Error code (if error).
message: Option<String>Error message (if error).
Implementations§
Source§impl Response
impl Response
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns true if this is a success response.
Sourcepub fn into_result(self) -> Result<Value>
pub fn into_result(self) -> Result<Value>
Extracts the result value, returning error if response was error.
§Errors
Returns Error::Protocol if the response was an error.
Sourcepub fn get_string(&self, key: &str) -> String
pub fn get_string(&self, key: &str) -> String
Gets a string value from the result.
Returns empty string if key not found or not a string.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Response
impl<'de> Deserialize<'de> for Response
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin 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