Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 80ea580

Browse files
Merge pull request #27 from botika/master
Fix SourceAnnotation ranges and refactor to `std::fmt::Display`
2 parents 7e73a1b + bdf43be commit 80ea580

23 files changed

+529
-613
lines changed

‎benches/simple.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
#![allow(clippy::unit_arg)]
12
#[macro_use]
23
extern crate criterion;
34

4-
use criterion::black_box;
5-
use criterion::Criterion;
5+
use criterion::{black_box, Criterion};
66

7-
use annotate_snippets::display_list::DisplayList;
8-
use annotate_snippets::formatter::DisplayListFormatter;
9-
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
7+
use annotate_snippets::{
8+
display_list::{DisplayList, FormatOptions},
9+
snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation},
10+
};
1011

1112
fn create_snippet() {
1213
let snippet = Snippet {
@@ -46,7 +47,7 @@ fn create_snippet() {
4647
SourceAnnotation {
4748
label: "expected enum `std::option::Option`".to_string(),
4849
annotation_type: AnnotationType::Error,
49-
range: (23,745),
50+
range: (26,724),
5051
},
5152
],
5253
}],
@@ -56,11 +57,14 @@ fn create_snippet() {
5657
annotation_type: AnnotationType::Error,
5758
}),
5859
footer: vec![],
60+
opt: FormatOptions {
61+
color: true,
62+
..Default::default()
63+
},
5964
};
6065

6166
let dl = DisplayList::from(snippet);
62-
let dlf = DisplayListFormatter::new(true, false);
63-
let _result = dlf.format(&dl);
67+
let _result = dl.to_string();
6468
}
6569

6670
pub fn criterion_benchmark(c: &mut Criterion) {

‎examples/expected_type.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use annotate_snippets::display_list::DisplayList;
2-
use annotate_snippets::formatter::DisplayListFormatter;
3-
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
1+
use annotate_snippets::{
2+
display_list::{DisplayList, FormatOptions},
3+
snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation},
4+
};
45

56
fn main() {
67
let snippet = Snippet {
@@ -23,7 +24,7 @@ fn main() {
2324
SourceAnnotation {
2425
label: "".to_string(),
2526
annotation_type: AnnotationType::Error,
26-
range: (208,210),
27+
range: (205,207),
2728
},
2829
SourceAnnotation {
2930
label: "while parsing this struct".to_string(),
@@ -32,9 +33,12 @@ fn main() {
3233
},
3334
],
3435
}],
36+
opt: FormatOptions {
37+
color: true,
38+
..Default::default()
39+
},
3540
};
3641

3742
let dl = DisplayList::from(snippet);
38-
let dlf = DisplayListFormatter::new(true, false);
39-
println!("{}", dlf.format(&dl));
43+
println!("{}", dl);
4044
}

‎examples/footer.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use annotate_snippets::display_list::DisplayList;
2-
use annotate_snippets::formatter::DisplayListFormatter;
3-
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
1+
use annotate_snippets::{
2+
display_list::{DisplayList, FormatOptions},
3+
snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation},
4+
};
45

56
fn main() {
67
let snippet = Snippet {
@@ -29,9 +30,12 @@ fn main() {
2930
annotation_type: AnnotationType::Error,
3031
}],
3132
}],
33+
opt: FormatOptions {
34+
color: true,
35+
..Default::default()
36+
},
3237
};
3338

3439
let dl = DisplayList::from(snippet);
35-
let dlf = DisplayListFormatter::new(true, false);
36-
println!("{}", dlf.format(&dl));
40+
println!("{}", dl);
3741
}

‎examples/format.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use annotate_snippets::display_list::DisplayList;
2-
use annotate_snippets::formatter::DisplayListFormatter;
3-
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
1+
use annotate_snippets::{
2+
display_list::{DisplayList, FormatOptions},
3+
snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation},
4+
};
45

56
fn main() {
67
let snippet = Snippet {
@@ -40,7 +41,7 @@ fn main() {
4041
SourceAnnotation {
4142
label: "expected enum `std::option::Option`".to_string(),
4243
annotation_type: AnnotationType::Error,
43-
range: (23,745),
44+
range: (26,724),
4445
},
4546
],
4647
}],
@@ -50,9 +51,12 @@ fn main() {
5051
annotation_type: AnnotationType::Error,
5152
}),
5253
footer: vec![],
54+
opt: FormatOptions {
55+
color: true,
56+
..Default::default()
57+
},
5358
};
5459

5560
let dl = DisplayList::from(snippet);
56-
let dlf = DisplayListFormatter::new(true, false);
57-
println!("{}", dlf.format(&dl));
61+
println!("{}", dl);
5862
}

‎examples/multislice.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use annotate_snippets::display_list::DisplayList;
2-
use annotate_snippets::formatter::DisplayListFormatter;
3-
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet};
1+
use annotate_snippets::{
2+
display_list::{DisplayList, FormatOptions},
3+
snippet::{Annotation, AnnotationType, Slice, Snippet},
4+
};
45

56
fn main() {
67
let snippet = Snippet {
@@ -26,9 +27,12 @@ fn main() {
2627
annotations: vec![],
2728
},
2829
],
30+
opt: FormatOptions {
31+
color: true,
32+
..Default::default()
33+
},
2934
};
3035

3136
let dl = DisplayList::from(snippet);
32-
let dlf = DisplayListFormatter::new(true, false);
33-
println!("{}", dlf.format(&dl));
37+
println!("{}", dl);
3438
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /