#[non_exhaustive]
pub enum Pos {
    None,
    Unknown,
    Invalid(usize),
    Byte {
        off: usize,
    },
    PosInLine {
        line: usize,
        byte: usize,
    },
    Raw {
        ptr: *const u8,
    },
}
Expand description

A position within a directory object. Used to tell where an error occurred.

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.

None

The error did not occur at any particular position.

This can happen when the error is something like a missing entry: the entry is supposed to go somewhere, but we can’t say where.

Unknown

The error occurred at an unknown position.

We should avoid using this case.

Invalid(usize)

The error occurred at an invalid offset within the string, or outside the string entirely.

This can only occur because of an internal error of some kind.

Byte

Fields

off: usize

Byte offset within a string.

The error occurred at a particular byte within the string.

We try to convert these to a Pos before displaying them to the user.

PosInLine

Fields

line: usize

Line offset within a string.

byte: usize

Byte offset within the line.

The error occurred at a particular line (and possibly at a particular byte within the line.)

Raw

Fields

ptr: *const u8

A raw pointer to the position where the error occurred.

The error occurred at a position in memory. This shouldn’t be exposed to the user, but rather should be mapped to a position in the string.

Implementations

Construct a Pos from an offset within a &str slice.

Construct a Pos from a slice of some other string. This Pos won’t be terribly helpful, but it may be converted into a useful Pos with within.

Construct Pos from the end of some other string.

Construct a position from a byte offset.

Construct a position from a line and a byte offset within that line.

Given a position, if it was at a byte offset, convert it to a line-and-byte position within s.

Requires that this position was actually generated from s. If it was not, the results here may be nonsensical.

TODO: I wish I knew an efficient safe way to do this that guaranteed that we we always talking about the right string.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.