pub struct Cursor<T> { /* private fields */ }Expand description
A Cursor wraps an in-memory buffer and provides it with a
Seek implementation.
Cursors are used with in-memory buffers, anything implementing
AsRef<[u8]>, to allow them to implement Read and/or Write,
allowing these buffers to be used anywhere you might use a reader or writer
that does actual I/O.
The standard library implements some I/O traits on various types which
are commonly used as a buffer, like Cursor<Vec<u8>> and
Cursor<&[u8]>.
§Examples
We may want to write bytes to a File in our production
code, but use an in-memory buffer in our tests. We can do this with
Cursor:
use std::io::prelude::*;
use std::io::{self, SeekFrom};
use std::fs::File;
// a library function we've written
fn write_ten_bytes_at_end<W: Write + Seek>(mut writer: W) -> io::Result<()> {
    writer.seek(SeekFrom::End(-10))?;
    for i in 0..10 {
        writer.write(&[i])?;
    }
    // all went well
    Ok(())
}
// Here's some code that uses this library function.
//
// We might want to use a BufReader here for efficiency, but let's
// keep this example focused.
let mut file = File::create("foo.txt")?;
// First, we need to allocate 10 bytes to be able to write into.
file.set_len(10)?;
write_ten_bytes_at_end(&mut file)?;
// now let's write a test
#[test]
fn test_writes_bytes() {
    // setting up a real File is much slower than an in-memory buffer,
    // let's use a cursor instead
    use std::io::Cursor;
    let mut buff = Cursor::new(vec![0; 15]);
    write_ten_bytes_at_end(&mut buff).unwrap();
    assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
}Implementations§
Source§impl<T> Cursor<T>
 
impl<T> Cursor<T>
1.0.0 (const: 1.79.0) · Sourcepub const fn new(inner: T) -> Cursor<T> ⓘ
 
pub const fn new(inner: T) -> Cursor<T> ⓘ
Creates a new cursor wrapping the provided underlying in-memory buffer.
Cursor initial position is 0 even if underlying buffer (e.g., Vec)
is not empty. So writing to cursor starts with overwriting Vec
content, not with appending to it.
§Examples
use std::io::Cursor;
let buff = Cursor::new(Vec::new());1.0.0 · Sourcepub fn into_inner(self) -> T
 
pub fn into_inner(self) -> T
Consumes this cursor, returning the underlying value.
§Examples
use std::io::Cursor;
let buff = Cursor::new(Vec::new());
let vec = buff.into_inner();1.0.0 (const: 1.79.0) · Sourcepub const fn get_ref(&self) -> &T
 
pub const fn get_ref(&self) -> &T
Gets a reference to the underlying value in this cursor.
§Examples
use std::io::Cursor;
let buff = Cursor::new(Vec::new());
let reference = buff.get_ref();1.0.0 (const: 1.86.0) · Sourcepub const fn get_mut(&mut self) -> &mut T
 
pub const fn get_mut(&mut self) -> &mut T
Gets a mutable reference to the underlying value in this cursor.
Care should be taken to avoid modifying the internal I/O state of the underlying value as it may corrupt this cursor’s position.
§Examples
use std::io::Cursor;
let mut buff = Cursor::new(Vec::new());
let reference = buff.get_mut();1.0.0 (const: 1.79.0) · Sourcepub const fn position(&self) -> u64
 
pub const fn position(&self) -> u64
Returns the current position of this cursor.
§Examples
use std::io::Cursor;
use std::io::prelude::*;
use std::io::SeekFrom;
let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
assert_eq!(buff.position(), 0);
buff.seek(SeekFrom::Current(2)).unwrap();
assert_eq!(buff.position(), 2);
buff.seek(SeekFrom::Current(-1)).unwrap();
assert_eq!(buff.position(), 1);1.0.0 (const: 1.86.0) · Sourcepub const fn set_position(&mut self, pos: u64)
 
pub const fn set_position(&mut self, pos: u64)
Sets the position of this cursor.
§Examples
use std::io::Cursor;
let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
assert_eq!(buff.position(), 0);
buff.set_position(2);
assert_eq!(buff.position(), 2);
buff.set_position(4);
assert_eq!(buff.position(), 4);Source§impl<T> Cursor<T>
 
impl<T> Cursor<T>
Sourcepub fn split(&self) -> (&[u8], &[u8])
 🔬This is a nightly-only experimental API. (cursor_split)
pub fn split(&self) -> (&[u8], &[u8])
cursor_split)Splits the underlying slice at the cursor position and returns them.
§Examples
#![feature(cursor_split)]
use std::io::Cursor;
let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
assert_eq!(buff.split(), ([].as_slice(), [1, 2, 3, 4, 5].as_slice()));
buff.set_position(2);
assert_eq!(buff.split(), ([1, 2].as_slice(), [3, 4, 5].as_slice()));
buff.set_position(6);
assert_eq!(buff.split(), ([1, 2, 3, 4, 5].as_slice(), [].as_slice()));Source§impl<T> Cursor<T>
 
impl<T> Cursor<T>
Sourcepub fn split_mut(&mut self) -> (&mut [u8], &mut [u8])
 🔬This is a nightly-only experimental API. (cursor_split)
pub fn split_mut(&mut self) -> (&mut [u8], &mut [u8])
cursor_split)Splits the underlying slice at the cursor position and returns them mutably.
§Examples
#![feature(cursor_split)]
use std::io::Cursor;
let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
assert_eq!(buff.split_mut(), ([].as_mut_slice(), [1, 2, 3, 4, 5].as_mut_slice()));
buff.set_position(2);
assert_eq!(buff.split_mut(), ([1, 2].as_mut_slice(), [3, 4, 5].as_mut_slice()));
buff.set_position(6);
assert_eq!(buff.split_mut(), ([1, 2, 3, 4, 5].as_mut_slice(), [].as_mut_slice()));Trait Implementations§
Source§impl<T> AsyncBufRead for Cursor<T>
 
impl<T> AsyncBufRead for Cursor<T>
Source§impl AsyncWrite for Cursor<&mut [u8]>
 
impl AsyncWrite for Cursor<&mut [u8]>
Source§fn poll_write(
    self: Pin<&mut Cursor<&mut [u8]>>,
    _: &mut Context<'_>,
    buf: &[u8],
) -> Poll<Result<usize, Error>>
 
fn poll_write( self: Pin<&mut Cursor<&mut [u8]>>, _: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
buf into the object. Read moreSource§fn poll_write_vectored(
    self: Pin<&mut Cursor<&mut [u8]>>,
    _: &mut Context<'_>,
    bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, Error>>
 
fn poll_write_vectored( self: Pin<&mut Cursor<&mut [u8]>>, _: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>
poll_write, except that it writes from a slice of buffers. Read moreSource§fn is_write_vectored(&self) -> bool
 
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moreSource§impl AsyncWrite for Cursor<&mut Vec<u8>>
 
impl AsyncWrite for Cursor<&mut Vec<u8>>
Source§fn poll_write(
    self: Pin<&mut Cursor<&mut Vec<u8>>>,
    _: &mut Context<'_>,
    buf: &[u8],
) -> Poll<Result<usize, Error>>
 
fn poll_write( self: Pin<&mut Cursor<&mut Vec<u8>>>, _: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
buf into the object. Read moreSource§fn poll_write_vectored(
    self: Pin<&mut Cursor<&mut Vec<u8>>>,
    _: &mut Context<'_>,
    bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, Error>>
 
fn poll_write_vectored( self: Pin<&mut Cursor<&mut Vec<u8>>>, _: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>
poll_write, except that it writes from a slice of buffers. Read moreSource§fn is_write_vectored(&self) -> bool
 
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moreSource§impl AsyncWrite for Cursor<Box<[u8]>>
 
impl AsyncWrite for Cursor<Box<[u8]>>
Source§fn poll_write(
    self: Pin<&mut Cursor<Box<[u8]>>>,
    _: &mut Context<'_>,
    buf: &[u8],
) -> Poll<Result<usize, Error>>
 
fn poll_write( self: Pin<&mut Cursor<Box<[u8]>>>, _: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
buf into the object. Read moreSource§fn poll_write_vectored(
    self: Pin<&mut Cursor<Box<[u8]>>>,
    _: &mut Context<'_>,
    bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, Error>>
 
fn poll_write_vectored( self: Pin<&mut Cursor<Box<[u8]>>>, _: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>
poll_write, except that it writes from a slice of buffers. Read moreSource§fn is_write_vectored(&self) -> bool
 
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moreSource§impl AsyncWrite for Cursor<Vec<u8>>
 
impl AsyncWrite for Cursor<Vec<u8>>
Source§fn poll_write(
    self: Pin<&mut Cursor<Vec<u8>>>,
    _: &mut Context<'_>,
    buf: &[u8],
) -> Poll<Result<usize, Error>>
 
fn poll_write( self: Pin<&mut Cursor<Vec<u8>>>, _: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
buf into the object. Read moreSource§fn poll_write_vectored(
    self: Pin<&mut Cursor<Vec<u8>>>,
    _: &mut Context<'_>,
    bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, Error>>
 
fn poll_write_vectored( self: Pin<&mut Cursor<Vec<u8>>>, _: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>
poll_write, except that it writes from a slice of buffers. Read moreSource§fn is_write_vectored(&self) -> bool
 
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moreSource§impl<T> Buf for Cursor<T>
 
impl<T> Buf for Cursor<T>
Source§fn remaining(&self) -> usize
 
fn remaining(&self) -> usize
Source§fn chunk(&self) -> &[u8] ⓘ
 
fn chunk(&self) -> &[u8] ⓘ
Buf::remaining(). Note that this can return a shorter slice (this
allows non-continuous internal representation). Read moreSource§fn chunks_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize
 
fn chunks_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize
Source§fn has_remaining(&self) -> bool
 
fn has_remaining(&self) -> bool
Source§fn copy_to_slice(&mut self, dst: &mut [u8])
 
fn copy_to_slice(&mut self, dst: &mut [u8])
Source§fn get_u16(&mut self) -> u16
 
fn get_u16(&mut self) -> u16
self in big-endian byte order. Read moreSource§fn get_u16_le(&mut self) -> u16
 
fn get_u16_le(&mut self) -> u16
self in little-endian byte order. Read moreSource§fn get_u16_ne(&mut self) -> u16
 
fn get_u16_ne(&mut self) -> u16
self in native-endian byte order. Read moreSource§fn get_i16(&mut self) -> i16
 
fn get_i16(&mut self) -> i16
self in big-endian byte order. Read moreSource§fn get_i16_le(&mut self) -> i16
 
fn get_i16_le(&mut self) -> i16
self in little-endian byte order. Read moreSource§fn get_i16_ne(&mut self) -> i16
 
fn get_i16_ne(&mut self) -> i16
self in native-endian byte order. Read moreSource§fn get_u32(&mut self) -> u32
 
fn get_u32(&mut self) -> u32
self in the big-endian byte order. Read moreSource§fn get_u32_le(&mut self) -> u32
 
fn get_u32_le(&mut self) -> u32
self in the little-endian byte order. Read moreSource§fn get_u32_ne(&mut self) -> u32
 
fn get_u32_ne(&mut self) -> u32
self in native-endian byte order. Read moreSource§fn get_i32(&mut self) -> i32
 
fn get_i32(&mut self) -> i32
self in big-endian byte order. Read moreSource§fn get_i32_le(&mut self) -> i32
 
fn get_i32_le(&mut self) -> i32
self in little-endian byte order. Read moreSource§fn get_i32_ne(&mut self) -> i32
 
fn get_i32_ne(&mut self) -> i32
self in native-endian byte order. Read moreSource§fn get_u64(&mut self) -> u64
 
fn get_u64(&mut self) -> u64
self in big-endian byte order. Read moreSource§fn get_u64_le(&mut self) -> u64
 
fn get_u64_le(&mut self) -> u64
self in little-endian byte order. Read moreSource§fn get_u64_ne(&mut self) -> u64
 
fn get_u64_ne(&mut self) -> u64
self in native-endian byte order. Read moreSource§fn get_i64(&mut self) -> i64
 
fn get_i64(&mut self) -> i64
self in big-endian byte order. Read moreSource§fn get_i64_le(&mut self) -> i64
 
fn get_i64_le(&mut self) -> i64
self in little-endian byte order. Read moreSource§fn get_i64_ne(&mut self) -> i64
 
fn get_i64_ne(&mut self) -> i64
self in native-endian byte order. Read moreSource§fn get_u128(&mut self) -> u128
 
fn get_u128(&mut self) -> u128
self in big-endian byte order. Read moreSource§fn get_u128_le(&mut self) -> u128
 
fn get_u128_le(&mut self) -> u128
self in little-endian byte order. Read moreSource§fn get_u128_ne(&mut self) -> u128
 
fn get_u128_ne(&mut self) -> u128
self in native-endian byte order. Read moreSource§fn get_i128(&mut self) -> i128
 
fn get_i128(&mut self) -> i128
self in big-endian byte order. Read moreSource§fn get_i128_le(&mut self) -> i128
 
fn get_i128_le(&mut self) -> i128
self in little-endian byte order. Read moreSource§fn get_i128_ne(&mut self) -> i128
 
fn get_i128_ne(&mut self) -> i128
self in native-endian byte order. Read moreSource§fn get_uint(&mut self, nbytes: usize) -> u64
 
fn get_uint(&mut self, nbytes: usize) -> u64
self in big-endian byte order. Read moreSource§fn get_uint_le(&mut self, nbytes: usize) -> u64
 
fn get_uint_le(&mut self, nbytes: usize) -> u64
self in little-endian byte order. Read moreSource§fn get_uint_ne(&mut self, nbytes: usize) -> u64
 
fn get_uint_ne(&mut self, nbytes: usize) -> u64
self in native-endian byte order. Read moreSource§fn get_int(&mut self, nbytes: usize) -> i64
 
fn get_int(&mut self, nbytes: usize) -> i64
self in big-endian byte order. Read moreSource§fn get_int_le(&mut self, nbytes: usize) -> i64
 
fn get_int_le(&mut self, nbytes: usize) -> i64
self in little-endian byte order. Read moreSource§fn get_int_ne(&mut self, nbytes: usize) -> i64
 
fn get_int_ne(&mut self, nbytes: usize) -> i64
self in native-endian byte order. Read moreSource§fn get_f32(&mut self) -> f32
 
fn get_f32(&mut self) -> f32
self in big-endian byte order. Read moreSource§fn get_f32_le(&mut self) -> f32
 
fn get_f32_le(&mut self) -> f32
self in little-endian byte order. Read moreSource§fn get_f32_ne(&mut self) -> f32
 
fn get_f32_ne(&mut self) -> f32
self in native-endian byte order. Read moreSource§fn get_f64(&mut self) -> f64
 
fn get_f64(&mut self) -> f64
self in big-endian byte order. Read moreSource§fn get_f64_le(&mut self) -> f64
 
fn get_f64_le(&mut self) -> f64
self in little-endian byte order. Read moreSource§fn get_f64_ne(&mut self) -> f64
 
fn get_f64_ne(&mut self) -> f64
self in native-endian byte order. Read moreSource§fn try_copy_to_slice(&mut self, dst: &mut [u8]) -> Result<(), TryGetError>
 
fn try_copy_to_slice(&mut self, dst: &mut [u8]) -> Result<(), TryGetError>
Source§fn try_get_u8(&mut self) -> Result<u8, TryGetError>
 
fn try_get_u8(&mut self) -> Result<u8, TryGetError>
self. Read moreSource§fn try_get_i8(&mut self) -> Result<i8, TryGetError>
 
fn try_get_i8(&mut self) -> Result<i8, TryGetError>
self. Read moreSource§fn try_get_u16(&mut self) -> Result<u16, TryGetError>
 
fn try_get_u16(&mut self) -> Result<u16, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_u16_le(&mut self) -> Result<u16, TryGetError>
 
fn try_get_u16_le(&mut self) -> Result<u16, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_u16_ne(&mut self) -> Result<u16, TryGetError>
 
fn try_get_u16_ne(&mut self) -> Result<u16, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_i16(&mut self) -> Result<i16, TryGetError>
 
fn try_get_i16(&mut self) -> Result<i16, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_i16_le(&mut self) -> Result<i16, TryGetError>
 
fn try_get_i16_le(&mut self) -> Result<i16, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_i16_ne(&mut self) -> Result<i16, TryGetError>
 
fn try_get_i16_ne(&mut self) -> Result<i16, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_u32(&mut self) -> Result<u32, TryGetError>
 
fn try_get_u32(&mut self) -> Result<u32, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_u32_le(&mut self) -> Result<u32, TryGetError>
 
fn try_get_u32_le(&mut self) -> Result<u32, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_u32_ne(&mut self) -> Result<u32, TryGetError>
 
fn try_get_u32_ne(&mut self) -> Result<u32, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_i32(&mut self) -> Result<i32, TryGetError>
 
fn try_get_i32(&mut self) -> Result<i32, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_i32_le(&mut self) -> Result<i32, TryGetError>
 
fn try_get_i32_le(&mut self) -> Result<i32, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_i32_ne(&mut self) -> Result<i32, TryGetError>
 
fn try_get_i32_ne(&mut self) -> Result<i32, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_u64(&mut self) -> Result<u64, TryGetError>
 
fn try_get_u64(&mut self) -> Result<u64, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_u64_le(&mut self) -> Result<u64, TryGetError>
 
fn try_get_u64_le(&mut self) -> Result<u64, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_u64_ne(&mut self) -> Result<u64, TryGetError>
 
fn try_get_u64_ne(&mut self) -> Result<u64, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_i64(&mut self) -> Result<i64, TryGetError>
 
fn try_get_i64(&mut self) -> Result<i64, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_i64_le(&mut self) -> Result<i64, TryGetError>
 
fn try_get_i64_le(&mut self) -> Result<i64, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_i64_ne(&mut self) -> Result<i64, TryGetError>
 
fn try_get_i64_ne(&mut self) -> Result<i64, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_u128(&mut self) -> Result<u128, TryGetError>
 
fn try_get_u128(&mut self) -> Result<u128, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_u128_le(&mut self) -> Result<u128, TryGetError>
 
fn try_get_u128_le(&mut self) -> Result<u128, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_u128_ne(&mut self) -> Result<u128, TryGetError>
 
fn try_get_u128_ne(&mut self) -> Result<u128, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_i128(&mut self) -> Result<i128, TryGetError>
 
fn try_get_i128(&mut self) -> Result<i128, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_i128_le(&mut self) -> Result<i128, TryGetError>
 
fn try_get_i128_le(&mut self) -> Result<i128, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_i128_ne(&mut self) -> Result<i128, TryGetError>
 
fn try_get_i128_ne(&mut self) -> Result<i128, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_uint(&mut self, nbytes: usize) -> Result<u64, TryGetError>
 
fn try_get_uint(&mut self, nbytes: usize) -> Result<u64, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_uint_le(&mut self, nbytes: usize) -> Result<u64, TryGetError>
 
fn try_get_uint_le(&mut self, nbytes: usize) -> Result<u64, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_uint_ne(&mut self, nbytes: usize) -> Result<u64, TryGetError>
 
fn try_get_uint_ne(&mut self, nbytes: usize) -> Result<u64, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_int(&mut self, nbytes: usize) -> Result<i64, TryGetError>
 
fn try_get_int(&mut self, nbytes: usize) -> Result<i64, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_int_le(&mut self, nbytes: usize) -> Result<i64, TryGetError>
 
fn try_get_int_le(&mut self, nbytes: usize) -> Result<i64, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_int_ne(&mut self, nbytes: usize) -> Result<i64, TryGetError>
 
fn try_get_int_ne(&mut self, nbytes: usize) -> Result<i64, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_f32(&mut self) -> Result<f32, TryGetError>
 
fn try_get_f32(&mut self) -> Result<f32, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_f32_le(&mut self) -> Result<f32, TryGetError>
 
fn try_get_f32_le(&mut self) -> Result<f32, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_f32_ne(&mut self) -> Result<f32, TryGetError>
 
fn try_get_f32_ne(&mut self) -> Result<f32, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_f64(&mut self) -> Result<f64, TryGetError>
 
fn try_get_f64(&mut self) -> Result<f64, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_f64_le(&mut self) -> Result<f64, TryGetError>
 
fn try_get_f64_le(&mut self) -> Result<f64, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_f64_ne(&mut self) -> Result<f64, TryGetError>
 
fn try_get_f64_ne(&mut self) -> Result<f64, TryGetError>
self in native-endian byte order. Read moreSource§fn copy_to_bytes(&mut self, len: usize) -> Bytes
 
fn copy_to_bytes(&mut self, len: usize) -> Bytes
1.0.0 · Source§impl<T> BufRead for Cursor<T>
 
impl<T> BufRead for Cursor<T>
Source§fn fill_buf(&mut self) -> Result<&[u8], Error>
 
fn fill_buf(&mut self) -> Result<&[u8], Error>
Read methods, if empty. Read moreSource§fn consume(&mut self, amt: usize)
 
fn consume(&mut self, amt: usize)
amount of additional bytes from the internal buffer as having been read.
Subsequent calls to read only return bytes that have not been marked as read. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
 
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left)read. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
 
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
byte or EOF is reached. Read more1.0.0 · Source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
 
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA byte) is reached, and append
them to the provided String buffer. Read more1.0.0 · Source§impl<T> Read for Cursor<T>
 
impl<T> Read for Cursor<T>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
 
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
Source§fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
 
fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
 
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
 
fn is_read_vectored(&self) -> bool
can_vector)Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
 
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
 
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read moreSource§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
 
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read moreSource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
 
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
    Self: Sized,
 
fn by_ref(&mut self) -> &mut Selfwhere
    Self: Sized,
Read. Read more1.0.0 · Source§impl<T> Seek for Cursor<T>
 
impl<T> Seek for Cursor<T>
Source§fn seek(&mut self, style: SeekFrom) -> Result<u64, Error>
 
fn seek(&mut self, style: SeekFrom) -> Result<u64, Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
 
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)Source§fn stream_position(&mut self) -> Result<u64, Error>
 
fn stream_position(&mut self) -> Result<u64, Error>
1.0.0 · Source§impl Write for Cursor<&mut [u8]>
 
impl Write for Cursor<&mut [u8]>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
 
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn is_write_vectored(&self) -> bool
 
fn is_write_vectored(&self) -> bool
can_vector)Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
 
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
 
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Source§fn flush(&mut self) -> Result<(), Error>
 
fn flush(&mut self) -> Result<(), Error>
1.25.0 · Source§impl<A> Write for Cursor<&mut Vec<u8, A>>where
    A: Allocator,
 
impl<A> Write for Cursor<&mut Vec<u8, A>>where
    A: Allocator,
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
 
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn is_write_vectored(&self) -> bool
 
fn is_write_vectored(&self) -> bool
can_vector)Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
 
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
 
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Source§fn flush(&mut self) -> Result<(), Error>
 
fn flush(&mut self) -> Result<(), Error>
1.61.0 · Source§impl<const N: usize> Write for Cursor<[u8; N]>
 
impl<const N: usize> Write for Cursor<[u8; N]>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
 
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn is_write_vectored(&self) -> bool
 
fn is_write_vectored(&self) -> bool
can_vector)Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
 
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
 
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Source§fn flush(&mut self) -> Result<(), Error>
 
fn flush(&mut self) -> Result<(), Error>
1.5.0 · Source§impl<A> Write for Cursor<Box<[u8], A>>where
    A: Allocator,
 
impl<A> Write for Cursor<Box<[u8], A>>where
    A: Allocator,
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
 
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn is_write_vectored(&self) -> bool
 
fn is_write_vectored(&self) -> bool
can_vector)Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
 
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
 
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Source§fn flush(&mut self) -> Result<(), Error>
 
fn flush(&mut self) -> Result<(), Error>
1.0.0 · Source§impl<A> Write for Cursor<Vec<u8, A>>where
    A: Allocator,
 
impl<A> Write for Cursor<Vec<u8, A>>where
    A: Allocator,
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
 
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn is_write_vectored(&self) -> bool
 
fn is_write_vectored(&self) -> bool
can_vector)Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
 
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
 
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Source§fn flush(&mut self) -> Result<(), Error>
 
fn flush(&mut self) -> Result<(), Error>
impl<T> Eq for Cursor<T>where
    T: Eq,
impl<T> StructuralPartialEq for Cursor<T>
Auto Trait Implementations§
impl<T> Freeze for Cursor<T>where
    T: Freeze,
impl<T> RefUnwindSafe for Cursor<T>where
    T: RefUnwindSafe,
impl<T> Send for Cursor<T>where
    T: Send,
impl<T> Sync for Cursor<T>where
    T: Sync,
impl<T> Unpin for Cursor<T>where
    T: Unpin,
impl<T> UnwindSafe for Cursor<T>where
    T: UnwindSafe,
Blanket Implementations§
Source§impl<R> AsyncBufReadExt for Rwhere
    R: AsyncBufRead + ?Sized,
 
impl<R> AsyncBufReadExt for Rwhere
    R: AsyncBufRead + ?Sized,
Source§fn read_until<'a>(
    &'a mut self,
    byte: u8,
    buf: &'a mut Vec<u8>,
) -> ReadUntil<'a, Self>where
    Self: Unpin,
 
fn read_until<'a>(
    &'a mut self,
    byte: u8,
    buf: &'a mut Vec<u8>,
) -> ReadUntil<'a, Self>where
    Self: Unpin,
Source§fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self>where
    Self: Unpin,
 
fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self>where
    Self: Unpin,
Source§fn split(self, byte: u8) -> Split<Self>
 
fn split(self, byte: u8) -> Split<Self>
byte. Read moreSource§fn fill_buf(&mut self) -> FillBuf<'_, Self>where
    Self: Unpin,
 
fn fill_buf(&mut self) -> FillBuf<'_, Self>where
    Self: Unpin,
Source§impl<R> AsyncReadExt for R
 
impl<R> AsyncReadExt for R
Source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
    Self: Unpin,
 
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
    Self: Unpin,
Source§fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
 
fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
Source§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
    Self: Unpin,
 
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
    Self: Unpin,
buf. Read moreSource§fn read_u8(&mut self) -> ReadU8<&mut Self>where
    Self: Unpin,
 
fn read_u8(&mut self) -> ReadU8<&mut Self>where
    Self: Unpin,
Source§fn read_i8(&mut self) -> ReadI8<&mut Self>where
    Self: Unpin,
 
fn read_i8(&mut self) -> ReadI8<&mut Self>where
    Self: Unpin,
Source§fn read_u16(&mut self) -> ReadU16<&mut Self>where
    Self: Unpin,
 
fn read_u16(&mut self) -> ReadU16<&mut Self>where
    Self: Unpin,
Source§fn read_i16(&mut self) -> ReadI16<&mut Self>where
    Self: Unpin,
 
fn read_i16(&mut self) -> ReadI16<&mut Self>where
    Self: Unpin,
Source§fn read_u32(&mut self) -> ReadU32<&mut Self>where
    Self: Unpin,
 
fn read_u32(&mut self) -> ReadU32<&mut Self>where
    Self: Unpin,
Source§fn read_i32(&mut self) -> ReadI32<&mut Self>where
    Self: Unpin,
 
fn read_i32(&mut self) -> ReadI32<&mut Self>where
    Self: Unpin,
Source§fn read_u64(&mut self) -> ReadU64<&mut Self>where
    Self: Unpin,
 
fn read_u64(&mut self) -> ReadU64<&mut Self>where
    Self: Unpin,
Source§fn read_i64(&mut self) -> ReadI64<&mut Self>where
    Self: Unpin,
 
fn read_i64(&mut self) -> ReadI64<&mut Self>where
    Self: Unpin,
Source§fn read_u128(&mut self) -> ReadU128<&mut Self>where
    Self: Unpin,
 
fn read_u128(&mut self) -> ReadU128<&mut Self>where
    Self: Unpin,
Source§fn read_i128(&mut self) -> ReadI128<&mut Self>where
    Self: Unpin,
 
fn read_i128(&mut self) -> ReadI128<&mut Self>where
    Self: Unpin,
Source§fn read_f32(&mut self) -> ReadF32<&mut Self>where
    Self: Unpin,
 
fn read_f32(&mut self) -> ReadF32<&mut Self>where
    Self: Unpin,
Source§fn read_f64(&mut self) -> ReadF64<&mut Self>where
    Self: Unpin,
 
fn read_f64(&mut self) -> ReadF64<&mut Self>where
    Self: Unpin,
Source§fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
    Self: Unpin,
 
fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
    Self: Unpin,
Source§fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
    Self: Unpin,
 
fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
    Self: Unpin,
Source§fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
    Self: Unpin,
 
fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
    Self: Unpin,
Source§fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
    Self: Unpin,
 
fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
    Self: Unpin,
Source§fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
    Self: Unpin,
 
fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
    Self: Unpin,
Source§fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
    Self: Unpin,
 
fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
    Self: Unpin,
Source§fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
    Self: Unpin,
 
fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
    Self: Unpin,
Source§fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
    Self: Unpin,
 
fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
    Self: Unpin,
Source§fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
    Self: Unpin,
 
fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
    Self: Unpin,
Source§fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
    Self: Unpin,
 
fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
    Self: Unpin,
Source§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
    Self: Unpin,
 
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
    Self: Unpin,
buf. Read moreSource§impl<S> AsyncSeekExt for S
 
impl<S> AsyncSeekExt for S
Source§fn seek(&mut self, pos: SeekFrom) -> Seek<'_, Self>where
    Self: Unpin,
 
fn seek(&mut self, pos: SeekFrom) -> Seek<'_, Self>where
    Self: Unpin,
Source§fn rewind(&mut self) -> Seek<'_, Self>where
    Self: Unpin,
 
fn rewind(&mut self) -> Seek<'_, Self>where
    Self: Unpin,
Source§fn stream_position(&mut self) -> Seek<'_, Self>where
    Self: Unpin,
 
fn stream_position(&mut self) -> Seek<'_, Self>where
    Self: Unpin,
Source§impl<W> AsyncWriteExt for Wwhere
    W: AsyncWrite + ?Sized,
 
impl<W> AsyncWriteExt for Wwhere
    W: AsyncWrite + ?Sized,
Source§fn write<'a>(&'a mut self, src: &'a [u8]) -> Write<'a, Self>where
    Self: Unpin,
 
fn write<'a>(&'a mut self, src: &'a [u8]) -> Write<'a, Self>where
    Self: Unpin,
Source§fn write_vectored<'a, 'b>(
    &'a mut self,
    bufs: &'a [IoSlice<'b>],
) -> WriteVectored<'a, 'b, Self>where
    Self: Unpin,
 
fn write_vectored<'a, 'b>(
    &'a mut self,
    bufs: &'a [IoSlice<'b>],
) -> WriteVectored<'a, 'b, Self>where
    Self: Unpin,
Source§fn write_buf<'a, B>(&'a mut self, src: &'a mut B) -> WriteBuf<'a, Self, B>
 
fn write_buf<'a, B>(&'a mut self, src: &'a mut B) -> WriteBuf<'a, Self, B>
Source§fn write_all_buf<'a, B>(
    &'a mut self,
    src: &'a mut B,
) -> WriteAllBuf<'a, Self, B>
 
fn write_all_buf<'a, B>( &'a mut self, src: &'a mut B, ) -> WriteAllBuf<'a, Self, B>
Source§fn write_all<'a>(&'a mut self, src: &'a [u8]) -> WriteAll<'a, Self>where
    Self: Unpin,
 
fn write_all<'a>(&'a mut self, src: &'a [u8]) -> WriteAll<'a, Self>where
    Self: Unpin,
Source§fn write_u8(&mut self, n: u8) -> WriteU8<&mut Self>where
    Self: Unpin,
 
fn write_u8(&mut self, n: u8) -> WriteU8<&mut Self>where
    Self: Unpin,
Source§fn write_i8(&mut self, n: i8) -> WriteI8<&mut Self>where
    Self: Unpin,
 
fn write_i8(&mut self, n: i8) -> WriteI8<&mut Self>where
    Self: Unpin,
Source§fn write_u16(&mut self, n: u16) -> WriteU16<&mut Self>where
    Self: Unpin,
 
fn write_u16(&mut self, n: u16) -> WriteU16<&mut Self>where
    Self: Unpin,
Source§fn write_i16(&mut self, n: i16) -> WriteI16<&mut Self>where
    Self: Unpin,
 
fn write_i16(&mut self, n: i16) -> WriteI16<&mut Self>where
    Self: Unpin,
Source§fn write_u32(&mut self, n: u32) -> WriteU32<&mut Self>where
    Self: Unpin,
 
fn write_u32(&mut self, n: u32) -> WriteU32<&mut Self>where
    Self: Unpin,
Source§fn write_i32(&mut self, n: i32) -> WriteI32<&mut Self>where
    Self: Unpin,
 
fn write_i32(&mut self, n: i32) -> WriteI32<&mut Self>where
    Self: Unpin,
Source§fn write_u64(&mut self, n: u64) -> WriteU64<&mut Self>where
    Self: Unpin,
 
fn write_u64(&mut self, n: u64) -> WriteU64<&mut Self>where
    Self: Unpin,
Source§fn write_i64(&mut self, n: i64) -> WriteI64<&mut Self>where
    Self: Unpin,
 
fn write_i64(&mut self, n: i64) -> WriteI64<&mut Self>where
    Self: Unpin,
Source§fn write_u128(&mut self, n: u128) -> WriteU128<&mut Self>where
    Self: Unpin,
 
fn write_u128(&mut self, n: u128) -> WriteU128<&mut Self>where
    Self: Unpin,
Source§fn write_i128(&mut self, n: i128) -> WriteI128<&mut Self>where
    Self: Unpin,
 
fn write_i128(&mut self, n: i128) -> WriteI128<&mut Self>where
    Self: Unpin,
Source§fn write_f32(&mut self, n: f32) -> WriteF32<&mut Self>where
    Self: Unpin,
 
fn write_f32(&mut self, n: f32) -> WriteF32<&mut Self>where
    Self: Unpin,
Source§fn write_f64(&mut self, n: f64) -> WriteF64<&mut Self>where
    Self: Unpin,
 
fn write_f64(&mut self, n: f64) -> WriteF64<&mut Self>where
    Self: Unpin,
Source§fn write_u16_le(&mut self, n: u16) -> WriteU16Le<&mut Self>where
    Self: Unpin,
 
fn write_u16_le(&mut self, n: u16) -> WriteU16Le<&mut Self>where
    Self: Unpin,
Source§fn write_i16_le(&mut self, n: i16) -> WriteI16Le<&mut Self>where
    Self: Unpin,
 
fn write_i16_le(&mut self, n: i16) -> WriteI16Le<&mut Self>where
    Self: Unpin,
Source§fn write_u32_le(&mut self, n: u32) -> WriteU32Le<&mut Self>where
    Self: Unpin,
 
fn write_u32_le(&mut self, n: u32) -> WriteU32Le<&mut Self>where
    Self: Unpin,
Source§fn write_i32_le(&mut self, n: i32) -> WriteI32Le<&mut Self>where
    Self: Unpin,
 
fn write_i32_le(&mut self, n: i32) -> WriteI32Le<&mut Self>where
    Self: Unpin,
Source§fn write_u64_le(&mut self, n: u64) -> WriteU64Le<&mut Self>where
    Self: Unpin,
 
fn write_u64_le(&mut self, n: u64) -> WriteU64Le<&mut Self>where
    Self: Unpin,
Source§fn write_i64_le(&mut self, n: i64) -> WriteI64Le<&mut Self>where
    Self: Unpin,
 
fn write_i64_le(&mut self, n: i64) -> WriteI64Le<&mut Self>where
    Self: Unpin,
Source§fn write_u128_le(&mut self, n: u128) -> WriteU128Le<&mut Self>where
    Self: Unpin,
 
fn write_u128_le(&mut self, n: u128) -> WriteU128Le<&mut Self>where
    Self: Unpin,
Source§fn write_i128_le(&mut self, n: i128) -> WriteI128Le<&mut Self>where
    Self: Unpin,
 
fn write_i128_le(&mut self, n: i128) -> WriteI128Le<&mut Self>where
    Self: Unpin,
Source§fn write_f32_le(&mut self, n: f32) -> WriteF32Le<&mut Self>where
    Self: Unpin,
 
fn write_f32_le(&mut self, n: f32) -> WriteF32Le<&mut Self>where
    Self: Unpin,
Source§fn write_f64_le(&mut self, n: f64) -> WriteF64Le<&mut Self>where
    Self: Unpin,
 
fn write_f64_le(&mut self, n: f64) -> WriteF64Le<&mut Self>where
    Self: Unpin,
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
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
 
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> ExecutableCommand for T
 
impl<T> ExecutableCommand for T
Source§fn execute(&mut self, command: impl Command) -> Result<&mut T, Error>
 
fn execute(&mut self, command: impl Command) -> Result<&mut T, Error>
Executes the given command directly.
The given command its ANSI escape code will be written and flushed onto Self.
§Arguments
- 
The command that you want to execute directly. 
§Example
use std::io;
use crossterm::{ExecutableCommand, style::Print};
fn main() -> io::Result<()> {
     // will be executed directly
      io::stdout()
        .execute(Print("sum:\n".to_string()))?
        .execute(Print(format!("1 + 1= {} ", 1 + 1)))?;
      Ok(())
     // ==== Output ====
     // sum:
     // 1 + 1 = 2
}Have a look over at the Command API for more details.
§Notes
- In the case of UNIX and Windows 10, ANSI codes are written to the given ‘writer’.
- In case of Windows versions lower than 10, a direct WinAPI call will be made.
The reason for this is that Windows versions lower than 10 do not support ANSI codes,
and can therefore not be written to the given writer. Therefore, there is no difference between execute and queue for those old Windows versions.
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
 
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> QueueableCommand for T
 
impl<T> QueueableCommand for T
Source§fn queue(&mut self, command: impl Command) -> Result<&mut T, Error>
 
fn queue(&mut self, command: impl Command) -> Result<&mut T, Error>
Queues the given command for further execution.
Queued commands will be executed in the following cases:
- When flushis called manually on the given type implementingio::Write.
- The terminal will flushautomatically if the buffer is full.
- Each line is flushed in case of stdout, because it is line buffered.
§Arguments
- 
The command that you want to queue for later execution. 
§Examples
use std::io::{self, Write};
use crossterm::{QueueableCommand, style::Print};
 fn main() -> io::Result<()> {
    let mut stdout = io::stdout();
    // `Print` will executed executed when `flush` is called.
    stdout
        .queue(Print("foo 1\n".to_string()))?
        .queue(Print("foo 2".to_string()))?;
    // some other code (no execution happening here) ...
    // when calling `flush` on `stdout`, all commands will be written to the stdout and therefore executed.
    stdout.flush()?;
    Ok(())
    // ==== Output ====
    // foo 1
    // foo 2
}Have a look over at the Command API for more details.
§Notes
- In the case of UNIX and Windows 10, ANSI codes are written to the given ‘writer’.
- In case of Windows versions lower than 10, a direct WinAPI call will be made.
The reason for this is that Windows versions lower than 10 do not support ANSI codes,
and can therefore not be written to the given writer. Therefore, there is no difference between execute and queue for those old Windows versions.
Source§impl<W> SynchronizedUpdate for W
 
impl<W> SynchronizedUpdate for W
Source§fn sync_update<T>(
    &mut self,
    operations: impl FnOnce(&mut W) -> T,
) -> Result<T, Error>
 
fn sync_update<T>( &mut self, operations: impl FnOnce(&mut W) -> T, ) -> Result<T, Error>
Performs a set of actions within a synchronous update.
Updates will be suspended in the terminal, the function will be executed against self, updates will be resumed, and a flush will be performed.
§Arguments
- 
Function A function that performs the operations that must execute in a synchronized update. 
§Examples
use std::io;
use crossterm::{ExecutableCommand, SynchronizedUpdate, style::Print};
fn main() -> io::Result<()> {
    let mut stdout = io::stdout();
    stdout.sync_update(|stdout| {
        stdout.execute(Print("foo 1\n".to_string()))?;
        stdout.execute(Print("foo 2".to_string()))?;
        // The effects of the print command will not be present in the terminal
        // buffer, but not visible in the terminal.
        std::io::Result::Ok(())
    })?;
    // The effects of the commands will be visible.
    Ok(())
    // ==== Output ====
    // foo 1
    // foo 2
}§Notes
This command is performed only using ANSI codes, and will do nothing on terminals that do not support ANSI codes, or this specific extension.
When rendering the screen of the terminal, the Emulator usually iterates through each visible grid cell and renders its current state. With applications updating the screen a at higher frequency this can cause tearing.
This mode attempts to mitigate that.
When the synchronization mode is enabled following render calls will keep rendering the last rendered state. The terminal Emulator keeps processing incoming text and sequences. When the synchronized update mode is disabled again the renderer may fetch the latest screen buffer state again, effectively avoiding the tearing effect by unintentionally rendering in the middle a of an application screen update.