Skip to main content

Span

Struct Span 

Source
pub struct Span { /* private fields */ }
Expand description

Where one field’s bytes are in the buffer it was read from.

A quoted field’s range is what is between its quotes. Whether a doubled quote or an escaped one is in there is kept too, since then the bytes are not the value yet and Span::text has to take the escapes out, which is the one case that copies before the value is used.

Eight bytes, two u32s with the escape in the top bit of the end, because a chunk holds one of these for every field of eight thousand records and the converters walk them once per column. That caps a chunk’s buffer at Span::MOST bytes, which the reader keeps to.

Implementations§

Source§

impl Span

Source

pub const MOST: usize

The furthest into its buffer a range can reach.

Source

pub fn new(start: usize, end: usize, escaped: bool) -> Self

The field from start to end, with escapes in it or not.

§Panics

In a debug build, if end is past Self::MOST, which the reader never lets a buffer be.

Source

pub const fn start(self) -> usize

The first byte of the field.

Source

pub const fn end(self) -> usize

One past the last byte of the field.

Source

pub const fn escaped(self) -> bool

Whether the bytes still hold escapes.

Source

pub const fn is_empty(self) -> bool

Whether the field is empty, which the reader turns into a null unless it was told a different null string.

A field with an escape in it is never empty once the escape is taken out, since every escape leaves a byte behind, so the range answers for the value.

Source

pub const fn len(self) -> usize

How many bytes the field has in the buffer, escapes and all.

Source

pub fn raw(self, bytes: &[u8]) -> &[u8] ⓘ

The bytes of the field as they are in the buffer, escapes and all.

Source

pub fn text(self, bytes: &[u8], dialect: Dialect) -> Cow<'_, str>

The field as text, borrowed from the buffer unless it had an escape or a byte that is not UTF-8 in it.

The bytes that are not UTF-8 become the replacement character, exactly as String::from_utf8_lossy makes them, because that is what record does and the two have to agree.

Trait Implementations§

Source§

impl Clone for Span

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Span

Source§

impl Debug for Span

Source§

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

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

impl Eq for Span

Source§

impl PartialEq for Span

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Span

Auto Trait Implementations§

§

impl Freeze for Span

§

impl RefUnwindSafe for Span

§

impl Send for Span

§

impl Sync for Span

§

impl Unpin for Span

§

impl UnsafeUnpin for Span

§

impl UnwindSafe for Span

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.