pub fn new(sock: &str) -> Result<Connection> {

        let mut newsock = UnixStream::connect(sock)?;
        let mut newbuffer = [0u8; 2048];

        // read the inital "OK MPD 1.2.3" string from the socket
        match newsock.read(&mut newbuffer) {
            Ok(value) => if !newbuffer.starts_with(b"OK MPD") { 
                             panic!("Could connect but MPD is not okay:\n{}", value);
                         }
            Err(error) => panic!("Could not connect to socket!\n{}", error),
        }

        Ok(Connection {
            stream: newsock,
            buffer: newbuffer, 
        })
    }
/// Connects to MPD and stores the connection details
///
/// You first have to connect to MPD in order to control it.
/// Start a new connection wth this "new" function.
///
/// # Arguments
/// * 'sock' - A string slice containing the path to the MPD Unix socket.
///
/// # Returns
/// You get a Connection struct back, with connection and buffer in it.
/// It's inside a Result type, so errors propagate upstream with this one.
Connects to MPD and stores the connection details
You first have to connect to MPD in order to control it.
Start a new connection wth this "new" function.
Connects to MPD and stores the connection details You first have to connect to MPD in order to control it . Start a new connection wth this " new " function .
pub fn new(sock: &str) -> Result<Connection> {
        let mut newsock = UnixStream::connect(sock)?;
        let mut newbuffer = [0u8; 2048];
        // read the inital "OK MPD 1.2.3" string from the socket
        match newsock.read(&mut newbuffer) {
            Ok(value) => if !newbuffer.starts_with(b"OK MPD") { 
                             panic!("Could connect but MPD is not okay:\n{}", value);
                         }
            Err(error) => panic!("Could not connect to socket!\n{}", error),
        }
        Ok(Connection {
            stream: newsock,
            buffer: newbuffer, 
        })
    }
pub fn new ( sock : & str ) -> Result < Connection > { let mut newsock = UnixStream :: connect ( sock ) ? ; let mut newbuffer = [ 0u8 ; 2048 ] ; // read the inital "OK MPD 1.2.3" string from the socket match newsock . read ( & mut newbuffer ) { Ok ( value ) => if ! newbuffer . starts_with ( b" " ) { panic ! ( " \n " value ) ; } Err ( error ) => panic ! ( " \n " error ) , } Ok ( Connection { stream : newsock , buffer : newbuffer , } ) }
Connects to MPD and stores the connection details
You first have to connect to MPD in order to control it.
Connects to MPD and stores the connection details You first have to connect to MPD in order to control it .
sock
&str
You get a Connection struct back, with connection and buffer in it.
It's inside a Result type, so errors propagate upstream with this one.
You get a Connection struct back with connection and buffer in it . It ' s inside a Result type so errors propagate upstream with this one .
sock
&str