pub struct Span {
pub start: usize,
pub end: usize,
pub escaped: bool,
}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. escaped says a doubled quote or an
escaped one is in there, so 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.
Fields§
§start: usizeThe first byte of the field.
end: usizeOne past the last byte of the field.
escaped: boolWhether the bytes still hold escapes.
Implementations§
Source§impl Span
impl Span
Sourcepub const fn is_empty(self) -> bool
pub const fn is_empty(self) -> bool
Whether the field is empty, which the reader turns into a null.
A field with an escape in it is never empty once the escape is taken out, since every escape leaves a quote behind, so the range answers for the value.
Sourcepub fn raw(self, bytes: &[u8]) -> &[u8] ⓘ
pub fn raw(self, bytes: &[u8]) -> &[u8] ⓘ
The bytes of the field as they are in the buffer, escapes and all.
Sourcepub fn text(self, bytes: &[u8], dialect: Dialect) -> Cow<'_, str>
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.