pub struct SimpleSource<'a> { /* private fields */ }
Expand description
Simple source container that holds the filename and source text. Ariadne will automatically handle row/column calculations from byte offsets.
§Usage Example
use bms_rs::bms::diagnostics::SimpleSource;
// Create source container
let source_text = "#TITLE test\n#ARTIST composer\n";
let source = SimpleSource::new("test.bms", source_text);
// Get source text
assert_eq!(source.text(), source_text);
Implementations§
Source§impl<'a> SimpleSource<'a>
impl<'a> SimpleSource<'a>
Sourcepub const fn new(name: &'a str, text: &'a str) -> Self
pub const fn new(name: &'a str, text: &'a str) -> Self
Create a new source container instance.
§Parameters
name
- Name of the source filetext
- Complete text content of the source file
Examples found in repository?
19fn demonstrate_warning_types() {
20 println!("1. Demonstrate ToAriadne implementation for all warning types:");
21
22 let source_text = "#TITLE Demo\n#ARTIST Composer\n";
23 let source = SimpleSource::new("demo.bms", source_text);
24
25 // Create various types of warnings
26 let warnings = vec![
27 BmsWarning::PlayingWarning(PlayingWarning::TotalUndefined),
28 BmsWarning::PlayingWarning(PlayingWarning::NoDisplayableNotes),
29 BmsWarning::PlayingWarning(PlayingWarning::NoPlayableNotes),
30 ];
31
32 println!(" Created {} warnings", warnings.len());
33
34 for (i, warning) in warnings.iter().enumerate() {
35 println!(" Warning {}: {}", i + 1, warning);
36
37 // Demonstrate ToAriadne trait usage
38 let _report = warning.to_report(&source);
39 println!(" -> Successfully converted to ariadne Report");
40 }
41}
42
43fn demonstrate_integration() {
44 println!("2. Complete integration workflow:");
45
46 // Parse a BMS file that may produce warnings
47 let bms_source = r#"#TITLE Integration Demo
48#ARTIST Composer
49#PLAYER 1
50#GENRE Demo
51#TOTAL 100
52
53#00001:01000000
54#00002:02000000
55"#;
56
57 println!(" Parsing BMS file...");
58 let output = parse_bms::<KeyLayoutBeat>(bms_source);
59
60 println!(
61 " Parsing completed, found {} warnings",
62 output.warnings.len()
63 );
64
65 if !output.warnings.is_empty() {
66 println!(" Using convenience function to output warnings:");
67 emit_bms_warnings("integration_demo.bms", bms_source, &output.warnings);
68
69 println!("\n Handling each warning manually:");
70 let source = SimpleSource::new("integration_demo.bms", bms_source);
71 let ariadne_source = ariadne::Source::from(bms_source);
72
73 for (i, warning) in output.warnings.iter().enumerate() {
74 println!(" Warning {}: {}", i + 1, warning);
75
76 // Manually convert to Report and print
77 let report = warning.to_report(&source);
78 let _ = report.print(("integration_demo.bms".to_string(), ariadne_source.clone()));
79 }
80 }
81
82 println!("\n Successfully demonstrated complete diagnostics integration workflow!");
83}
More examples
7fn main() {
8 // An example BMS file containing warnings
9 let bms_source = r#"#TITLE Test Song
10#ARTIST Test Composer
11#INVALID_COMMAND this will cause a warning
12#TOTAL 100
13
14#00111:01010101
15#00211:02020202
16"#;
17
18 println!("Parsing BMS file and displaying diagnostic information...\n");
19
20 // Parse BMS file
21 let output = parse_bms::<KeyLayoutBeat>(bms_source);
22
23 // Display parsing results
24 println!(
25 "Parsing successful! Found {} warnings",
26 output.warnings.len()
27 );
28
29 // Use diagnostics functionality to output beautiful diagnostic information
30 if !output.warnings.is_empty() {
31 println!("\n=== Diagnostic Information ===");
32 emit_bms_warnings("example.bms", bms_source, &output.warnings);
33 }
34
35 // Can also handle each warning manually
36 println!("\n=== Manual Warning Handling Example ===");
37 let source = SimpleSource::new("example.bms", bms_source);
38 let ariadne_source = ariadne::Source::from(bms_source);
39
40 for warning in &output.warnings {
41 let report = warning.to_report(&source);
42 let _ = report.print(("example.bms".to_string(), ariadne_source.clone()));
43 }
44
45 println!("\nBMS parsing completed!");
46}
Auto Trait Implementations§
impl<'a> Freeze for SimpleSource<'a>
impl<'a> RefUnwindSafe for SimpleSource<'a>
impl<'a> Send for SimpleSource<'a>
impl<'a> Sync for SimpleSource<'a>
impl<'a> Unpin for SimpleSource<'a>
impl<'a> UnwindSafe for SimpleSource<'a>
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> 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>
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>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
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>
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>
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>
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>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
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 rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
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);
Source§impl<T> SourceRangeMixinExt for T
impl<T> SourceRangeMixinExt for T
Source§fn into_wrapper<W>(
self,
wrapper: &SourceRangeMixin<W>,
) -> SourceRangeMixin<Self>where
Self: Sized,
fn into_wrapper<W>(
self,
wrapper: &SourceRangeMixin<W>,
) -> SourceRangeMixin<Self>where
Self: Sized,
SourceRangeMixin
with the same span as a wrapper.Source§fn into_wrapper_range(self, range: Range<usize>) -> SourceRangeMixin<Self>where
Self: Sized,
fn into_wrapper_range(self, range: Range<usize>) -> SourceRangeMixin<Self>where
Self: Sized,
SourceRangeMixin
with a given range.Source§fn into_wrapper_span(self, span: (usize, usize)) -> SourceRangeMixin<Self>where
Self: Sized,
fn into_wrapper_span(self, span: (usize, usize)) -> SourceRangeMixin<Self>where
Self: Sized,
SourceRangeMixin
with a given (start, end) span.