pub struct PathWithPosition {
pub path: PathBuf,
pub row: Option<u32>,
pub column: Option<u32>,
}Expand description
A representation of a path-like string with optional row and column numbers.
Matching values example: te, test.rs:22, te:22:5, test.c(22), test.c(22,5)etc.
Fields§
§path: PathBuf§row: Option<u32>§column: Option<u32>Implementations§
Source§impl PathWithPosition
impl PathWithPosition
Sourcepub fn parse_str(s: &str) -> Self
pub fn parse_str(s: &str) -> Self
Parses a string that possibly has :row:column or (row, column) suffix.
Parenthesis format is used by MSBuild compatible tools
Ignores trailing :s, so test.rs:22: is parsed as test.rs:22.
If the suffix parsing fails, the whole string is parsed as a path.
Be mindful that test_file:10:1: is a valid posix filename.
PathWithPosition class assumes that the ending position-like suffix is not part of the filename.
§Examples
assert_eq!(PathWithPosition::parse_str("test_file"), PathWithPosition {
path: PathBuf::from("test_file"),
row: None,
column: None,
});
assert_eq!(PathWithPosition::parse_str("test_file:10"), PathWithPosition {
path: PathBuf::from("test_file"),
row: Some(10),
column: None,
});
assert_eq!(PathWithPosition::parse_str("test_file.rs"), PathWithPosition {
path: PathBuf::from("test_file.rs"),
row: None,
column: None,
});
assert_eq!(PathWithPosition::parse_str("test_file.rs:1"), PathWithPosition {
path: PathBuf::from("test_file.rs"),
row: Some(1),
column: None,
});
assert_eq!(PathWithPosition::parse_str("test_file.rs:1:2"), PathWithPosition {
path: PathBuf::from("test_file.rs"),
row: Some(1),
column: Some(2),
});§Expected parsing results when encounter ill-formatted inputs.
assert_eq!(PathWithPosition::parse_str("test_file.rs:a"), PathWithPosition {
path: PathBuf::from("test_file.rs:a"),
row: None,
column: None,
});
assert_eq!(PathWithPosition::parse_str("test_file.rs:a:b"), PathWithPosition {
path: PathBuf::from("test_file.rs:a:b"),
row: None,
column: None,
});
assert_eq!(PathWithPosition::parse_str("test_file.rs"), PathWithPosition {
path: PathBuf::from("test_file.rs"),
row: None,
column: None,
});
assert_eq!(PathWithPosition::parse_str("test_file.rs::1"), PathWithPosition {
path: PathBuf::from("test_file.rs"),
row: Some(1),
column: None,
});
assert_eq!(PathWithPosition::parse_str("test_file.rs:1::"), PathWithPosition {
path: PathBuf::from("test_file.rs"),
row: Some(1),
column: None,
});
assert_eq!(PathWithPosition::parse_str("test_file.rs::1:2"), PathWithPosition {
path: PathBuf::from("test_file.rs"),
row: Some(1),
column: Some(2),
});
assert_eq!(PathWithPosition::parse_str("test_file.rs:1::2"), PathWithPosition {
path: PathBuf::from("test_file.rs:1"),
row: Some(2),
column: None,
});
assert_eq!(PathWithPosition::parse_str("test_file.rs:1:2:3"), PathWithPosition {
path: PathBuf::from("test_file.rs:1"),
row: Some(2),
column: Some(3),
});pub fn map_path<E>( self, mapping: impl FnOnce(PathBuf) -> Result<PathBuf, E>, ) -> Result<PathWithPosition, E>
pub fn to_string(&self, path_to_string: impl Fn(&PathBuf) -> String) -> String
Trait Implementations§
Source§impl Clone for PathWithPosition
impl Clone for PathWithPosition
Source§fn clone(&self) -> PathWithPosition
fn clone(&self) -> PathWithPosition
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PathWithPosition
impl Debug for PathWithPosition
Source§impl<'de> Deserialize<'de> for PathWithPosition
impl<'de> Deserialize<'de> for PathWithPosition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Hash for PathWithPosition
impl Hash for PathWithPosition
Source§impl PartialEq for PathWithPosition
impl PartialEq for PathWithPosition
Source§impl Serialize for PathWithPosition
impl Serialize for PathWithPosition
impl Eq for PathWithPosition
impl StructuralPartialEq for PathWithPosition
Auto Trait Implementations§
impl Freeze for PathWithPosition
impl RefUnwindSafe for PathWithPosition
impl Send for PathWithPosition
impl Sync for PathWithPosition
impl Unpin for PathWithPosition
impl UnwindSafe for PathWithPosition
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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