[−][src]Struct mpd_protocol::response::Response
Response to a command, consisting of an abitrary amount of frames, which are responses to individual commands, and optionally a single error.
Since an error terminates a command list, there can only be one error in a response.
Methods
impl Response
[src]
pub fn new(frames: Vec<Frame>, error: Option<Error>) -> Self
[src]
Construct a new response.
use mpd_protocol::response::{Response, Frame}; let r = Response::new(vec![Frame::empty()], None); assert_eq!(1, r.len()); assert!(r.is_success());
Panics
Panics if it is attempted to construct an empty response (i.e. both frames
and error
are empty). This should not occur during normal operation.
use mpd_protocol::response::Response; // This panics: Response::new(Vec::new(), None);
pub fn empty() -> Self
[src]
Construct a new "empty" response. This is the simplest possible succesful response, consisting of a single empty frame.
use mpd_protocol::response::Response; let r = Response::empty(); assert_eq!(1, r.len()); assert!(r.is_success());
pub fn is_error(&self) -> bool
[src]
Returns true
if the response resulted in an error.
Even if this returns true
, there may still be succesful frames in the response when the
response is to a command list.
use mpd_protocol::response::{Response, Error}; let r = Response::new(Vec::new(), Some(Error::default())); assert!(r.is_error());
pub fn is_success(&self) -> bool
[src]
Returns true
if the response was entirely succesful (i.e. no errors).
use mpd_protocol::response::{Response, Frame}; let r = Response::new(vec![Frame::empty()], None); assert!(r.is_success());
pub fn len(&self) -> usize
[src]
Get the number of succesful frames in the response.
May be 0 if the response only consists of an error.
use mpd_protocol::response::Response; let r = Response::empty(); assert_eq!(r.len(), 1);
pub fn next_frame(self) -> Result<(Frame, Option<Self>), Error>
[src]
Get the next frame or error from the response as a Result
.
Includes the remaining portion of the response. A possible error always occurs as the last element, since it terminates command lists.
use mpd_protocol::response::{Response, Frame}; let r = Response::new(vec![Frame::empty(), Frame::empty()], None); let res = r.next_frame().unwrap(); assert_eq!(Frame::empty(), res.0); assert_eq!(Ok((Frame::empty(), None)), res.1.unwrap().next_frame());
pub fn single_frame(self) -> Result<Frame, Error>
[src]
Treat the response as consisting of a single frame or error.
Frames or errors beyond the first, if they exist, are silently discarded.
use mpd_protocol::response::{Frame, Response}; let r = Response::empty(); assert_eq!(Ok(Frame::empty()), r.single_frame());
pub fn frames(self) -> impl Iterator<Item = Result<Frame, Error>>
[src]
Creates an iterator over all frames and errors in the response.
use mpd_protocol::response::{Frame, Response}; let mut first = vec![(String::from("hello"), String::from("world"))]; let second = vec![(String::from("foo"), String::from("bar"))]; let mut iter = Response::new(vec![Frame { values: first.clone(), binary: None, }, Frame { values: second.clone(), binary: None, }], None).frames(); assert_eq!(Some(Ok(Frame { values: first, binary: None, })), iter.next()); assert_eq!(Some(Ok(Frame { values: second, binary: None, })), iter.next()); assert_eq!(None, iter.next());
Trait Implementations
impl Debug for Response
[src]
impl Eq for Response
[src]
impl PartialEq<Response> for Response
[src]
impl StructuralEq for Response
[src]
impl StructuralPartialEq for Response
[src]
Auto Trait Implementations
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,