#[non_exhaustive]pub enum ColumnEncoding {
Utf8,
Scalar,
Utf16,
}Expand description
The unit that a Position column counts.
The same byte offset has a different column in each unit when the line
holds characters outside ASCII. Pick the unit your consumer expects: byte
columns for Rust string slicing, scalar columns for counting chars, and
UTF-16 columns for the Language Server Protocol and JavaScript editors.
No unit is a terminal display width: a tab counts as one unit, and a
combining accent counts as a character of its own.
§Examples
use adotenv::{ColumnEncoding, LineIndex};
// `é` takes 2 bytes and `😀` takes 4 bytes or 2 UTF-16 units.
let source = "NAME=é😀!\n";
let index = LineIndex::new(source);
let offset = source.find('!').unwrap();
assert_eq!(offset, 11);
assert_eq!(index.to_position(offset, ColumnEncoding::Utf8)?.column, 11);
assert_eq!(index.to_position(offset, ColumnEncoding::Scalar)?.column, 7);
assert_eq!(index.to_position(offset, ColumnEncoding::Utf16)?.column, 8);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Utf8
Bytes of UTF-8.
A byte column can point inside a multi-byte character.
Scalar
Unicode scalar values, the units of Rust’s char.
Utf16
UTF-16 code units.
A character outside the Basic Multilingual Plane, such as most emoji, takes two units (a surrogate pair).
Trait Implementations§
Source§impl Clone for ColumnEncoding
impl Clone for ColumnEncoding
impl Copy for ColumnEncoding
Source§impl Debug for ColumnEncoding
impl Debug for ColumnEncoding
impl Eq for ColumnEncoding
Source§impl Hash for ColumnEncoding
impl Hash for ColumnEncoding
Source§impl PartialEq for ColumnEncoding
impl PartialEq for ColumnEncoding
impl StructuralPartialEq for ColumnEncoding
Auto Trait Implementations§
impl Forget for ColumnEncoding
impl Freeze for ColumnEncoding
impl Move for ColumnEncoding
impl RefUnwindSafe for ColumnEncoding
impl Send for ColumnEncoding
impl Sync for ColumnEncoding
impl Unpin for ColumnEncoding
impl UnsafeUnpin for ColumnEncoding
impl UnwindSafe for ColumnEncoding
Blanket Implementations§
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
Mutably borrows from an owned value. Read more