Skip to main content

Cursor

Struct Cursor 

Source
pub struct Cursor<T> { /* private fields */ }
Expand description

A cursor-like writer structure returned by FStr::writer_at.

See the FStr::writer_at documentation for the detailed behavior of this type’s fmt::Write implementation.

§Examples

use core::fmt::Write as _;

let mut buffer = FStr::<20>::from_ascii_filler(b'.');
assert_eq!(buffer, "....................");

let mut cursor = buffer.writer_at(0);
assert_eq!(cursor.position(), 0);
assert_eq!(&cursor.get_ref()[..], "....................");

write!(cursor, "gentle")?;
assert_eq!(cursor.position(), 6);
assert_eq!(&cursor.get_ref()[..], "gentle..............");

write!(cursor, " flamingo")?;
assert_eq!(cursor.position(), 15);
assert_eq!(&cursor.get_ref()[..], "gentle flamingo.....");

assert_eq!(
    cursor.get_ref().split_at(cursor.position()),
    ("gentle flamingo", ".....")
);

assert_eq!(buffer, "gentle flamingo.....");

Implementations§

Source§

impl<T> Cursor<T>

Source

pub fn get_ref(&self) -> &T

Gets a reference to the underlying value in this cursor.

Source

pub fn position(&self) -> usize

Returns the current position of this cursor.

Trait Implementations§

Source§

impl<T: Debug> Debug for Cursor<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: AsMut<str>> Write for Cursor<T>

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

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

Glue for usage of the write! macro with implementors of this trait. Read more

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> UnsafeUnpin for Cursor<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Cursor<T>
where T: 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, 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>,

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.