Struct BorrowedCursor

Source
pub struct BorrowedCursor<'a> { /* private fields */ }
๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)
Expand description

A writeable view of the unfilled portion of a BorrowedBuf.

The unfilled portion consists of an initialized and an uninitialized part; see BorrowedBuf for details.

Data can be written directly to the cursor by using append or indirectly by getting a slice of part or all of the cursor and writing into the slice. In the indirect case, the caller must call advance after writing to inform the cursor how many bytes have been written.

Once data is written to the cursor, it becomes part of the filled portion of the underlying BorrowedBuf and can no longer be accessed or re-written by the cursor. I.e., the cursor tracks the unfilled part of the underlying BorrowedBuf.

The lifetime 'a is a bound on the lifetime of the underlying buffer (which means it is a bound on the data in that buffer by transitivity).

Implementationsยง

Sourceยง

impl<'a> BorrowedCursor<'a>

Source

pub fn reborrow<'this>(&'this mut self) -> BorrowedCursor<'this> โ“˜

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)

Reborrows this cursor by cloning it with a smaller lifetime.

Since a cursor maintains unique access to its underlying buffer, the borrowed cursor is not accessible while the new cursor exists.

Source

pub fn capacity(&self) -> usize

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)

Returns the available space in the cursor.

Source

pub fn written(&self) -> usize

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)

Returns the number of bytes written to the BorrowedBuf this cursor was created from.

In particular, the count returned is shared by all reborrows of the cursor.

Source

pub fn init_mut(&mut self) -> &mut [u8] โ“˜

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)

Returns a mutable reference to the initialized portion of the cursor.

Source

pub unsafe fn as_mut(&mut self) -> &mut [MaybeUninit<u8>]

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)

Returns a mutable reference to the whole cursor.

ยงSafety

The caller must not uninitialize any bytes in the initialized portion of the cursor.

Source

pub fn advance(&mut self, n: usize) -> &mut BorrowedCursor<'a> โ“˜

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)

Advances the cursor by asserting that n bytes have been filled.

After advancing, the n bytes are no longer accessible via the cursor and can only be accessed via the underlying buffer. I.e., the bufferโ€™s filled portion grows by n elements and its unfilled portion (and the capacity of this cursor) shrinks by n elements.

If less than n bytes initialized (by the cursorโ€™s point of view), set_init should be called first.

ยงPanics

Panics if there are less than n bytes initialized.

Source

pub unsafe fn advance_unchecked(&mut self, n: usize) -> &mut BorrowedCursor<'a> โ“˜

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)

Advances the cursor by asserting that n bytes have been filled.

After advancing, the n bytes are no longer accessible via the cursor and can only be accessed via the underlying buffer. I.e., the bufferโ€™s filled portion grows by n elements and its unfilled portion (and the capacity of this cursor) shrinks by n elements.

ยงSafety

The caller must ensure that the first n bytes of the cursor have been properly initialised.

Source

pub fn ensure_init(&mut self) -> &mut BorrowedCursor<'a> โ“˜

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)

Initializes all bytes in the cursor.

Source

pub unsafe fn set_init(&mut self, n: usize) -> &mut BorrowedCursor<'a> โ“˜

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)

Asserts that the first n unfilled bytes of the cursor are initialized.

BorrowedBuf assumes that bytes are never de-initialized, so this method does nothing when called with fewer bytes than are already known to be initialized.

ยงSafety

The caller must ensure that the first n bytes of the buffer have already been initialized.

Source

pub fn append(&mut self, buf: &[u8])

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)

Appends data to the cursor, advancing position within its buffer.

ยงPanics

Panics if self.capacity() is less than buf.len().

Source

pub fn with_unfilled_buf<T>( &mut self, f: impl FnOnce(&mut BorrowedBuf<'_>) -> T, ) -> T

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io_borrowed_buf)

Runs the given closure with a BorrowedBuf containing the unfilled part of the cursor.

This enables inspecting what was written to the cursor.

ยงPanics

Panics if the BorrowedBuf given to the closure is replaced by another one.

Trait Implementationsยง

Sourceยง

impl<'a> Debug for BorrowedCursor<'a>

Sourceยง

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

Formats the value using the given formatter. Read more
Sourceยง

impl<'data> From<BorrowedCursor<'data>> for BorrowedBuf<'data>

Creates a new BorrowedBuf from a cursor.

Use BorrowedCursor::with_unfilled_buf instead for a safer alternative.

Sourceยง

fn from(buf: BorrowedCursor<'data>) -> BorrowedBuf<'data>

Converts to this type from the input type.
Sourceยง

impl<'a> Write for BorrowedCursor<'a>

Sourceยง

fn write(&mut self, buf: &[u8]) -> Result<usize, Error>

Writes a buffer into this writer, returning how many bytes were written. Read more
Sourceยง

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Sourceยง

fn is_write_vectored(&self) -> bool

๐Ÿ”ฌThis is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Sourceยง

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Sourceยง

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

๐Ÿ”ฌThis is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
Sourceยง

fn flush(&mut self) -> Result<(), Error>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.0.0 ยท Sourceยง

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 ยท Sourceยง

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a โ€œby referenceโ€ adapter for this instance of Write. Read more

Auto Trait Implementationsยง

ยง

impl<'a> Freeze for BorrowedCursor<'a>

ยง

impl<'a> RefUnwindSafe for BorrowedCursor<'a>

ยง

impl<'a> Send for BorrowedCursor<'a>

ยง

impl<'a> Sync for BorrowedCursor<'a>

ยง

impl<'a> Unpin for BorrowedCursor<'a>

ยง

impl<'a> !UnwindSafe for BorrowedCursor<'a>

Blanket Implementationsยง

Sourceยง

impl<T> AggregateExpressionMethods for T

Sourceยง

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Sourceยง

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Sourceยง

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Sourceยง

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
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> Downcast for T
where T: Any,

Sourceยง

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Sourceยง

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Sourceยง

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Anyโ€™s vtable from &Traitโ€™s.
Sourceยง

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Anyโ€™s vtable from &mut Traitโ€™s.
Sourceยง

impl<T> DowncastSend for T
where T: Any + Send,

Sourceยง

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Sourceยง

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Sourceยง

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Sourceยง

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Sourceยง

impl<T> ExecutableCommand for T
where T: Write + ?Sized,

Sourceยง

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
  • Command

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

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

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

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self> โ“˜

Converts 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 more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ“˜
where F: FnOnce(&Self) -> bool,

Converts 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 more
Sourceยง

impl<T> IntoSql for T

Sourceยง

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Dieselโ€™s query builder. Read more
Sourceยง

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Dieselโ€™s query builder. Read more
Sourceยง

impl<T> Pointable for T

Sourceยง

const ALIGN: usize

The alignment of pointer.
Sourceยง

type Init = T

The type for initializers.
Sourceยง

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Sourceยง

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Sourceยง

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Sourceยง

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Sourceยง

impl<T> QueueableCommand for T
where T: Write + ?Sized,

Sourceยง

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 flush is called manually on the given type implementing io::Write.
  • The terminal will flush automatically if the buffer is full.
  • Each line is flushed in case of stdout, because it is line buffered.
ยงArguments
  • Command

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

Sourceยง

type Output = T

Should always be Self
Sourceยง

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Sourceยง

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Sourceยง

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Sourceยง

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Sourceยง

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Sourceยง

impl<W> SynchronizedUpdate for W
where W: Write + ?Sized,

Sourceยง

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.

Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

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

Sourceยง

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V

Sourceยง

impl<T> WindowExpressionMethods for T

Sourceยง

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Sourceยง

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Sourceยง

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Sourceยง

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Sourceยง

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more
Sourceยง

impl<W> WriteBytesExt for W
where W: Write + ?Sized,

Sourceยง

fn write_u8(&mut self, n: u8) -> Result<(), Error>

Writes an unsigned 8 bit integer to the underlying writer. Read more
Sourceยง

fn write_i8(&mut self, n: i8) -> Result<(), Error>

Writes a signed 8 bit integer to the underlying writer. Read more
Sourceยง

fn write_u16<T>(&mut self, n: u16) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 16 bit integer to the underlying writer. Read more
Sourceยง

fn write_i16<T>(&mut self, n: i16) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 16 bit integer to the underlying writer. Read more
Sourceยง

fn write_u24<T>(&mut self, n: u32) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 24 bit integer to the underlying writer. Read more
Sourceยง

fn write_i24<T>(&mut self, n: i32) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 24 bit integer to the underlying writer. Read more
Sourceยง

fn write_u32<T>(&mut self, n: u32) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 32 bit integer to the underlying writer. Read more
Sourceยง

fn write_i32<T>(&mut self, n: i32) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 32 bit integer to the underlying writer. Read more
Sourceยง

fn write_u48<T>(&mut self, n: u64) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 48 bit integer to the underlying writer. Read more
Sourceยง

fn write_i48<T>(&mut self, n: i64) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 48 bit integer to the underlying writer. Read more
Sourceยง

fn write_u64<T>(&mut self, n: u64) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 64 bit integer to the underlying writer. Read more
Sourceยง

fn write_i64<T>(&mut self, n: i64) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 64 bit integer to the underlying writer. Read more
Sourceยง

fn write_u128<T>(&mut self, n: u128) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 128 bit integer to the underlying writer.
Sourceยง

fn write_i128<T>(&mut self, n: i128) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 128 bit integer to the underlying writer.
Sourceยง

fn write_uint<T>(&mut self, n: u64, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned n-bytes integer to the underlying writer. Read more
Sourceยง

fn write_int<T>(&mut self, n: i64, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes a signed n-bytes integer to the underlying writer. Read more
Sourceยง

fn write_uint128<T>(&mut self, n: u128, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned n-bytes integer to the underlying writer. Read more
Sourceยง

fn write_int128<T>(&mut self, n: i128, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes a signed n-bytes integer to the underlying writer. Read more
Sourceยง

fn write_f32<T>(&mut self, n: f32) -> Result<(), Error>
where T: ByteOrder,

Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer. Read more
Sourceยง

fn write_f64<T>(&mut self, n: f64) -> Result<(), Error>
where T: ByteOrder,

Writes a IEEE754 double-precision (8 bytes) floating point number to the underlying writer. Read more
Sourceยง

impl<T> ErasedDestructor for T
where T: 'static,