pub struct PositionMarker {
pub source_slice: Range<usize>,
pub templated_slice: Range<usize>,
pub templated_file: TemplatedFile,
pub working_line_no: usize,
pub working_line_pos: usize,
}
Expand description
A reference to a position in a file.
Things to note:
- This combines the previous functionality of FilePositionMarker and EnrichedFilePositionMarker. Additionally it contains a reference to the original templated file.
- It no longer explicitly stores a line number or line position in the source or template. This is extrapolated from the templated file as required.
- Positions in the source and template are with slices and therefore identify ranges.
- Positions within the fixed file are identified with a line number and line position, which identify a point.
- Arithmetic comparisons are on the location in the fixed file.
Fields§
§source_slice: Range<usize>
§templated_slice: Range<usize>
§templated_file: TemplatedFile
§working_line_no: usize
§working_line_pos: usize
Implementations§
Source§impl PositionMarker
impl PositionMarker
Sourcepub fn new(
source_slice: Range<usize>,
templated_slice: Range<usize>,
templated_file: TemplatedFile,
working_line_no: Option<usize>,
working_line_pos: Option<usize>,
) -> Self
pub fn new( source_slice: Range<usize>, templated_slice: Range<usize>, templated_file: TemplatedFile, working_line_no: Option<usize>, working_line_pos: Option<usize>, ) -> Self
creates a PositionMarker
Unlike the Python version, post_init is embedded into the new function.
pub fn source_str(&self) -> &str
pub fn line_no(&self) -> usize
pub fn line_pos(&self) -> usize
pub fn from_child_markers<'a>( markers: impl Iterator<Item = &'a PositionMarker>, ) -> PositionMarker
Sourcepub fn source_position(&self) -> (usize, usize)
pub fn source_position(&self) -> (usize, usize)
Return the line and position of this marker in the source.
Sourcepub fn templated_position(&self) -> (usize, usize)
pub fn templated_position(&self) -> (usize, usize)
Return the line and position of this marker in the source.
pub fn working_loc_after(&self, raw: &str) -> (usize, usize)
Sourcepub fn infer_next_position(
raw: &str,
line_no: usize,
line_pos: usize,
) -> (usize, usize)
pub fn infer_next_position( raw: &str, line_no: usize, line_pos: usize, ) -> (usize, usize)
Using the raw string provided to infer the position of the next. Line position in 1-indexed.
Sourcepub fn working_loc(&self) -> (usize, usize)
pub fn working_loc(&self) -> (usize, usize)
Location tuple for the working position.
Sourcepub fn from_point(
source_point: usize,
templated_point: usize,
templated_file: TemplatedFile,
working_line_no: Option<usize>,
working_line_pos: Option<usize>,
) -> Self
pub fn from_point( source_point: usize, templated_point: usize, templated_file: TemplatedFile, working_line_no: Option<usize>, working_line_pos: Option<usize>, ) -> Self
Convenience method for creating point markers.
Sourcepub fn start_point_marker(&self) -> PositionMarker
pub fn start_point_marker(&self) -> PositionMarker
Get a point marker from the start.
pub fn end_point_marker(&self) -> PositionMarker
Sourcepub fn is_literal(&self) -> bool
pub fn is_literal(&self) -> bool
Infer literalness from context.
is_literal should return True if a fix can be applied across this area in the templated file while being confident that the fix is still appropriate in the source file. This obviously applies to any slices which are the same in the source and the templated files. Slices which are zero-length in the source are also SyntaxKind::Literal because they can’t be “broken” by any fixes, because they don’t exist in the source. This includes meta segments and any segments added during the fixing process.
This value is used for:
- Ignoring linting errors in templated sections.
- Whether iter_patches
can return without recursing.
- Whether certain rules (such as JJ01) are triggered.
pub fn from_points( start_point_marker: &PositionMarker, end_point_marker: &PositionMarker, ) -> PositionMarker
Trait Implementations§
Source§impl Clone for PositionMarker
impl Clone for PositionMarker
Source§fn clone(&self) -> PositionMarker
fn clone(&self) -> PositionMarker
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for PositionMarker
impl Debug for PositionMarker
Source§impl Default for PositionMarker
impl Default for PositionMarker
Source§impl PartialEq for PositionMarker
impl PartialEq for PositionMarker
Source§impl PartialOrd for PositionMarker
impl PartialOrd for PositionMarker
impl Eq for PositionMarker
Auto Trait Implementations§
impl Freeze for PositionMarker
impl RefUnwindSafe for PositionMarker
impl Send for PositionMarker
impl Sync for PositionMarker
impl Unpin for PositionMarker
impl UnwindSafe for PositionMarker
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
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
key
and return true
if they are equal.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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.bright_black());
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.bright_green());
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.bright_yellow());
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.bright_magenta());
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.bright_white());
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.on_bright_black());
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.on_bright_green());
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.on_bright_yellow());
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlue
.
§Example
println!("{}", value.on_bright_blue());
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.on_bright_magenta());
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightCyan
.
§Example
println!("{}", value.on_bright_cyan());
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.on_bright_white());
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::Underline
.
§Example
println!("{}", value.underline());
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::RapidBlink
.
§Example
println!("{}", value.rapid_blink());
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);