Enum tor_netdoc::Pos
source · [−]#[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
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
The error occurred at a particular line (and possibly at a particular byte within the line.)
Raw
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 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
Auto Trait Implementations
Blanket Implementations
Mutably borrows from an owned value. Read more