async fn decoder_async_demo() {
    use futures_lite::StreamExt as _; // for 'next' on the Stream

    let input =
        "@key1=val1;key2=true;key3=42 :sender!sender@server PRIVMSG #museun :this is a test\r\n";

    let source = input.repeat(5);
    // Cursor<Vec<u8>> impl std::io::Read. using it for this demo
    let reader = futures_lite::io::Cursor::new(source.into_bytes());

    // you can make a decoder over an std::io::Read
    let mut decoder = twitchchat::AsyncDecoder::new(reader);

    // you use use read_message than the 'msg' is borrowed until the next call of 'read_message'
    while let Ok(_msg) = decoder.read_message().await {
        // msg is borrowed from the decoder here
    }

    // you can get the inner reader out
    let mut reader = decoder.into_inner();
    // seek back to the beginning for this demo
    reader.set_position(0);

    {
        // you can also just give it a &mut Reader
        let _decoder = twitchchat::AsyncDecoder::new(&mut reader);
        // which will drop the decoder here and you'll still have the 'reader' from above
    }

    // the decoder is also an Stream.
    // when using the Stream you'll get an 'owned' message back.
    while let Some(msg) = twitchchat::AsyncDecoder::new(&mut reader).next().await {
        // and msg is owned here ('static)
        // error if it failed to parse, or an IO error.
        let _msg: messages::IrcMessage<'static> = msg.unwrap();
    }
}
// all of the Sync is also applicable to the Async version.
all of the Sync is also applicable to the Async version.
all of the Sync is also applicable to the Async version .
async fn decoder_async_demo() {
    use futures_lite::StreamExt as _; // for 'next' on the Stream
    let input =
        "@key1=val1;key2=true;key3=42 :sender!sender@server PRIVMSG #museun :this is a test\r\n";
    let source = input.repeat(5);
    // Cursor<Vec<u8>> impl std::io::Read. using it for this demo
    let reader = futures_lite::io::Cursor::new(source.into_bytes());
    // you can make a decoder over an std::io::Read
    let mut decoder = twitchchat::AsyncDecoder::new(reader);
    // you use use read_message than the 'msg' is borrowed until the next call of 'read_message'
    while let Ok(_msg) = decoder.read_message().await {
        // msg is borrowed from the decoder here
    }
    // you can get the inner reader out
    let mut reader = decoder.into_inner();
    // seek back to the beginning for this demo
    reader.set_position(0);
    {
        // you can also just give it a &mut Reader
        let _decoder = twitchchat::AsyncDecoder::new(&mut reader);
        // which will drop the decoder here and you'll still have the 'reader' from above
    }
    // the decoder is also an Stream.
    // when using the Stream you'll get an 'owned' message back.
    while let Some(msg) = twitchchat::AsyncDecoder::new(&mut reader).next().await {
        // and msg is owned here ('static)
        // error if it failed to parse, or an IO error.
        let _msg: messages::IrcMessage<'static> = msg.unwrap();
    }
}
async fn decoder_async_demo ( ) { use futures_lite :: StreamExt as _ ; // for 'next' on the Stream let input = " \r \n " ; let source = input . repeat ( 5 ) ; // Cursor<Vec<u8>> impl std::io::Read. using it for this demo let reader = futures_lite :: io :: Cursor :: new ( source . into_bytes ( ) ) ; // you can make a decoder over an std::io::Read let mut decoder = twitchchat :: AsyncDecoder :: new ( reader ) ; // you use use read_message than the 'msg' is borrowed until the next call of 'read_message' while let Ok ( _msg ) = decoder . read_message ( ) . await { // msg is borrowed from the decoder here } // you can get the inner reader out let mut reader = decoder . into_inner ( ) ; // seek back to the beginning for this demo reader . set_position ( 0 ) ; { // you can also just give it a &mut Reader let _decoder = twitchchat :: AsyncDecoder :: new ( & mut reader ) ; // which will drop the decoder here and you'll still have the 'reader' from above } // the decoder is also an Stream. // when using the Stream you'll get an 'owned' message back. while let Some ( msg ) = twitchchat :: AsyncDecoder :: new ( & mut reader ) . next ( ) . await { // and msg is owned here ('static) // error if it failed to parse, or an IO error. let _msg : messages :: IrcMessage < ' static > = msg . unwrap ( ) ; } }
all of the Sync is also applicable to the Async version.
all of the Sync is also applicable to the Async version .