pub struct AsyncConnection<IO>(/* private fields */);
Expand description

An asynchronous connection to an MPD server.

Implementations§

source§

impl<IO> AsyncConnection<IO>

source

pub async fn connect(io: IO) -> Result<AsyncConnection<IO>, MpdProtocolError>
where IO: AsyncRead + Unpin,

Available on crate feature async only.

Connect to an MPD server asynchronously.

§Errors

This will return an error if:

  • Reading from the given IO resource returns an error
  • A malformed greeting is received
  • The connection is closed before a complete greeting could be read
source

pub async fn send(&mut self, command: Command) -> Result<(), MpdProtocolError>
where IO: AsyncWrite + Unpin,

Available on crate feature async only.

Send a command.

§Errors

This will return an error if writing to the given IO resource fails.

source

pub async fn send_list( &mut self, command_list: CommandList ) -> Result<(), MpdProtocolError>
where IO: AsyncWrite + Unpin,

Available on crate feature async only.

Send a command list.

§Errors

This will return an error if writing to the given IO resource fails.

source

pub async fn receive(&mut self) -> Result<Option<Response>, MpdProtocolError>
where IO: AsyncRead + Unpin,

Available on crate feature async only.

Receive a response from the server.

This will return Ok(Some(..)) when a complete response has been received, or Ok(None) if the connection is closed cleanly.

§Errors

This will return an error if:

  • Reading from the given IO resource returns an error
  • Malformed response data is received
  • The connection is closed while a response is in progress
source

pub async fn command( &mut self, command: Command ) -> Result<Response, MpdProtocolError>
where IO: AsyncRead + AsyncWrite + Unpin,

Send a command and receive its response.

This is essentially a shorthand for AsyncConnection::send followed by AsyncConnection::receive.

§Errors

This will return an error if:

  • Writing to or reading from the connection returns an error
  • Malformed response data is received
  • The connection is closed
source

pub async fn command_list( &mut self, command_list: CommandList ) -> Result<Response, MpdProtocolError>
where IO: AsyncRead + AsyncWrite + Unpin,

Send a command list and receive its response(s).

This is essentially a shorthand for AsyncConnection::send_list followed by AsyncConnection::receive.

§Errors

This will return an error if:

  • Writing to or reading from the connection returns an error
  • Malformed response data is received
  • The connection is closed
source

pub fn protocol_version(&self) -> &str

Returns the protocol version the server is using.

source

pub fn into_inner(self) -> IO

Extract the connection instance.

Trait Implementations§

source§

impl<IO: Debug> Debug for AsyncConnection<IO>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<IO> RefUnwindSafe for AsyncConnection<IO>
where IO: RefUnwindSafe,

§

impl<IO> Send for AsyncConnection<IO>
where IO: Send,

§

impl<IO> Sync for AsyncConnection<IO>
where IO: Sync,

§

impl<IO> Unpin for AsyncConnection<IO>
where IO: Unpin,

§

impl<IO> UnwindSafe for AsyncConnection<IO>
where IO: UnwindSafe,

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

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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>,

§

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more