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
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§
source§impl Pos
impl Pos
sourcepub fn from_offset(s: &str, off: usize) -> Self
pub fn from_offset(s: &str, off: usize) -> Self
Construct a Pos from an offset within a &str slice.
sourcepub fn at(s: &str) -> Self
pub fn at(s: &str) -> Self
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
.
sourcepub fn from_line(line: usize, byte: usize) -> Self
pub fn from_line(line: usize, byte: usize) -> Self
Construct a position from a line and a byte offset within that line.
sourcepub fn within(self, s: &str) -> Self
pub fn within(self, s: &str) -> Self
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§
impl Copy for Pos
impl Eq for Pos
impl Send for Pos
impl StructuralPartialEq for Pos
impl Sync for Pos
Auto Trait Implementations§
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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more