pub struct ReportBuilder<'a> {
    pub source_map: &'a SourceMap,
    pub colors: ColorChoice,
    pub charset: CharSet,
    pub style: DisplayStyle,
}

Fields§

§source_map: &'a SourceMap§colors: ColorChoice§charset: CharSet§style: DisplayStyle

Implementations§

source§

impl ReportBuilder<'_>

A report builder.

A report builder is used to build a report.

Example:

use ara_source::source::Source;
use ara_source::source::SourceKind;
use ara_source::SourceMap;

use ara_reporting::builder::ReportBuilder;
use ara_reporting::Report;

let report = Report::new();
let source = SourceMap::new(vec![
    Source::inline(SourceKind::Script, "function main(): void {}"),
]);

let builder = ReportBuilder::new(&source);
assert_eq!(builder.source_map.sources[0].content, "function main(): void {}");
source

pub fn new(source_map: &SourceMap) -> ReportBuilder<'_>

Create a new report builder.

Examples found in repository?
examples/cross_file.rs (line 56)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
More examples
Hide additional examples
examples/compact.rs (line 57)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_charset(CharSet::Unicode)
        .with_colors(ColorChoice::Always)
        .with_style(DisplayStyle::Compact);

    builder.print(&report)
}
examples/comfortable.rs (line 57)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_charset(CharSet::Unicode)
        .with_colors(ColorChoice::Always)
        .with_style(DisplayStyle::Comfortable);

    builder.print(&report)
}
examples/simple.rs (line 48)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
fn main() -> Result<(), Error> {
    let origin = "example.ara";
    let code = r#"
$b = match $a {
    1 => 2,
    2 => 3,
    default => "string",
};
"#;

    let map = SourceMap::new(vec![Source::new(SourceKind::Script, origin, code)]);

    let report = Report::new()
        .with_issue(
            Issue::error("E0417", "`match` arms have incompatible types")
                .with_source(origin, 6, 67)
                .with_annotation(
                    Annotation::secondary(origin, 26, 27)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(origin, 38, 39)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(origin, 56, 64)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0417`"),
        )
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
examples/collection.rs (line 79)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
fn main() -> Result<(), Error> {
    let first_origin = "example.ara";
    let first_code = r#"
$b = match $a {
    1 => 2,
    2 => 3,
    default => "string",
};
"#;

    let second_origin = "example-2.ara";
    let second_code = r#"
function foo(Bar&float) {}
"#;

    let map = SourceMap::new(vec![
        Source::new(SourceKind::Script, first_origin, first_code),
        Source::new(SourceKind::Script, second_origin, second_code),
    ]);

    let first_report = Report::new()
        .with_issue(
            Issue::error("E0417", "`match` arms have incompatible types")
                .with_source(first_origin, 6, 67)
                .with_annotation(
                    Annotation::secondary(first_origin, 26, 27)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(first_origin, 38, 39)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(first_origin, 56, 64)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0417`"),
        )
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let second_report = Report::new()
        .with_issue(
            Issue::error(
                "P0015",
                "scalar type `float` cannot be used in an intersection",
            )
            .with_source(second_origin, 18, 23)
            .with_annotation(
                Annotation::secondary(second_origin, 17, 19)
                    .with_message("scalar type `float` cannot be used in an intersection"),
            )
            .with_note("a scalar type is either `int`, `float`, `string`, or `bool`.")
            .with_note("try using a different type for the intersection."),
        )
        .with_issue(Issue::bug("B0001", "failed to read the file"))
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let reports: ReportCollection = vec![&first_report, &second_report];

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&reports)
}
examples/example.rs (line 102)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![Source::inline(
        SourceKind::Script,
        r#"
function main(): int|string {
    $a = 1;
    $b = 2;

    $c = $a + $b;

    $b = match ($a) {
        1 => 2,
        2 => 3,
        default => "string",
    };

    return $c + $b;
}
"#,
    )]);

    let report = Report::new()
        .with_issue(
            Issue::error("E123", "some error here")
                .with_source(DEFAULT_NAME, 35, 41)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::warning("W123", "some warning here")
                .with_source(DEFAULT_NAME, 29, 187)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::warning("W124", "some warning here")
                .with_source(DEFAULT_NAME, 29, 187)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::note("N123", "some note here")
                .with_source(DEFAULT_NAME, 84, 163)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 121, 128)
                        .with_message("another annotation"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::help("H123", "some help here")
                .with_source(DEFAULT_NAME, 137, 147)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::bug("E123", "`match` arms have incompatible types")
                .with_source(DEFAULT_NAME, 84, 163)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 110, 111)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 148, 156)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0308`"),
        )
        .with_footer(ReportFooter::new("this is a report footer message"));

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
source

pub fn with_colors(self, colors: ColorChoice) -> Self

Set the color choice.

Example:


let builder = builder.with_colors(ColorChoice::Never);
assert_eq!(builder.colors, ColorChoice::Never);

let builder = builder.with_colors(ColorChoice::Always);
assert_eq!(builder.colors, ColorChoice::Always);

let builder = builder.with_colors(ColorChoice::Auto);
assert_eq!(builder.colors, ColorChoice::Auto);
Examples found in repository?
examples/cross_file.rs (line 57)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
More examples
Hide additional examples
examples/compact.rs (line 59)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_charset(CharSet::Unicode)
        .with_colors(ColorChoice::Always)
        .with_style(DisplayStyle::Compact);

    builder.print(&report)
}
examples/comfortable.rs (line 59)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_charset(CharSet::Unicode)
        .with_colors(ColorChoice::Always)
        .with_style(DisplayStyle::Comfortable);

    builder.print(&report)
}
examples/simple.rs (line 49)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
fn main() -> Result<(), Error> {
    let origin = "example.ara";
    let code = r#"
$b = match $a {
    1 => 2,
    2 => 3,
    default => "string",
};
"#;

    let map = SourceMap::new(vec![Source::new(SourceKind::Script, origin, code)]);

    let report = Report::new()
        .with_issue(
            Issue::error("E0417", "`match` arms have incompatible types")
                .with_source(origin, 6, 67)
                .with_annotation(
                    Annotation::secondary(origin, 26, 27)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(origin, 38, 39)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(origin, 56, 64)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0417`"),
        )
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
examples/collection.rs (line 80)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
fn main() -> Result<(), Error> {
    let first_origin = "example.ara";
    let first_code = r#"
$b = match $a {
    1 => 2,
    2 => 3,
    default => "string",
};
"#;

    let second_origin = "example-2.ara";
    let second_code = r#"
function foo(Bar&float) {}
"#;

    let map = SourceMap::new(vec![
        Source::new(SourceKind::Script, first_origin, first_code),
        Source::new(SourceKind::Script, second_origin, second_code),
    ]);

    let first_report = Report::new()
        .with_issue(
            Issue::error("E0417", "`match` arms have incompatible types")
                .with_source(first_origin, 6, 67)
                .with_annotation(
                    Annotation::secondary(first_origin, 26, 27)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(first_origin, 38, 39)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(first_origin, 56, 64)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0417`"),
        )
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let second_report = Report::new()
        .with_issue(
            Issue::error(
                "P0015",
                "scalar type `float` cannot be used in an intersection",
            )
            .with_source(second_origin, 18, 23)
            .with_annotation(
                Annotation::secondary(second_origin, 17, 19)
                    .with_message("scalar type `float` cannot be used in an intersection"),
            )
            .with_note("a scalar type is either `int`, `float`, `string`, or `bool`.")
            .with_note("try using a different type for the intersection."),
        )
        .with_issue(Issue::bug("B0001", "failed to read the file"))
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let reports: ReportCollection = vec![&first_report, &second_report];

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&reports)
}
examples/example.rs (line 103)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![Source::inline(
        SourceKind::Script,
        r#"
function main(): int|string {
    $a = 1;
    $b = 2;

    $c = $a + $b;

    $b = match ($a) {
        1 => 2,
        2 => 3,
        default => "string",
    };

    return $c + $b;
}
"#,
    )]);

    let report = Report::new()
        .with_issue(
            Issue::error("E123", "some error here")
                .with_source(DEFAULT_NAME, 35, 41)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::warning("W123", "some warning here")
                .with_source(DEFAULT_NAME, 29, 187)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::warning("W124", "some warning here")
                .with_source(DEFAULT_NAME, 29, 187)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::note("N123", "some note here")
                .with_source(DEFAULT_NAME, 84, 163)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 121, 128)
                        .with_message("another annotation"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::help("H123", "some help here")
                .with_source(DEFAULT_NAME, 137, 147)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::bug("E123", "`match` arms have incompatible types")
                .with_source(DEFAULT_NAME, 84, 163)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 110, 111)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 148, 156)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0308`"),
        )
        .with_footer(ReportFooter::new("this is a report footer message"));

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
source

pub fn with_charset(self, charset: CharSet) -> Self

Set the character set.

Example:


let builder = builder.with_charset(CharSet::Ascii);
assert_eq!(builder.charset, CharSet::Ascii);

let builder = builder.with_charset(CharSet::Unicode);
assert_eq!(builder.charset, CharSet::Unicode);
Examples found in repository?
examples/cross_file.rs (line 58)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
More examples
Hide additional examples
examples/compact.rs (line 58)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_charset(CharSet::Unicode)
        .with_colors(ColorChoice::Always)
        .with_style(DisplayStyle::Compact);

    builder.print(&report)
}
examples/comfortable.rs (line 58)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_charset(CharSet::Unicode)
        .with_colors(ColorChoice::Always)
        .with_style(DisplayStyle::Comfortable);

    builder.print(&report)
}
examples/simple.rs (line 50)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
fn main() -> Result<(), Error> {
    let origin = "example.ara";
    let code = r#"
$b = match $a {
    1 => 2,
    2 => 3,
    default => "string",
};
"#;

    let map = SourceMap::new(vec![Source::new(SourceKind::Script, origin, code)]);

    let report = Report::new()
        .with_issue(
            Issue::error("E0417", "`match` arms have incompatible types")
                .with_source(origin, 6, 67)
                .with_annotation(
                    Annotation::secondary(origin, 26, 27)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(origin, 38, 39)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(origin, 56, 64)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0417`"),
        )
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
examples/collection.rs (line 81)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
fn main() -> Result<(), Error> {
    let first_origin = "example.ara";
    let first_code = r#"
$b = match $a {
    1 => 2,
    2 => 3,
    default => "string",
};
"#;

    let second_origin = "example-2.ara";
    let second_code = r#"
function foo(Bar&float) {}
"#;

    let map = SourceMap::new(vec![
        Source::new(SourceKind::Script, first_origin, first_code),
        Source::new(SourceKind::Script, second_origin, second_code),
    ]);

    let first_report = Report::new()
        .with_issue(
            Issue::error("E0417", "`match` arms have incompatible types")
                .with_source(first_origin, 6, 67)
                .with_annotation(
                    Annotation::secondary(first_origin, 26, 27)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(first_origin, 38, 39)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(first_origin, 56, 64)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0417`"),
        )
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let second_report = Report::new()
        .with_issue(
            Issue::error(
                "P0015",
                "scalar type `float` cannot be used in an intersection",
            )
            .with_source(second_origin, 18, 23)
            .with_annotation(
                Annotation::secondary(second_origin, 17, 19)
                    .with_message("scalar type `float` cannot be used in an intersection"),
            )
            .with_note("a scalar type is either `int`, `float`, `string`, or `bool`.")
            .with_note("try using a different type for the intersection."),
        )
        .with_issue(Issue::bug("B0001", "failed to read the file"))
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let reports: ReportCollection = vec![&first_report, &second_report];

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&reports)
}
examples/example.rs (line 104)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![Source::inline(
        SourceKind::Script,
        r#"
function main(): int|string {
    $a = 1;
    $b = 2;

    $c = $a + $b;

    $b = match ($a) {
        1 => 2,
        2 => 3,
        default => "string",
    };

    return $c + $b;
}
"#,
    )]);

    let report = Report::new()
        .with_issue(
            Issue::error("E123", "some error here")
                .with_source(DEFAULT_NAME, 35, 41)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::warning("W123", "some warning here")
                .with_source(DEFAULT_NAME, 29, 187)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::warning("W124", "some warning here")
                .with_source(DEFAULT_NAME, 29, 187)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::note("N123", "some note here")
                .with_source(DEFAULT_NAME, 84, 163)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 121, 128)
                        .with_message("another annotation"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::help("H123", "some help here")
                .with_source(DEFAULT_NAME, 137, 147)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::bug("E123", "`match` arms have incompatible types")
                .with_source(DEFAULT_NAME, 84, 163)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 110, 111)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 148, 156)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0308`"),
        )
        .with_footer(ReportFooter::new("this is a report footer message"));

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
source

pub fn with_style(self, style: DisplayStyle) -> Self

Set the display style

Example:


let builder = builder.with_style(DisplayStyle::Default);
assert_eq!(builder.style, DisplayStyle::Default);

let builder = builder.with_style(DisplayStyle::Comfortable);
assert_eq!(builder.style, DisplayStyle::Comfortable);

let builder = builder.with_style(DisplayStyle::Compact);
assert_eq!(builder.style, DisplayStyle::Compact);
Examples found in repository?
examples/compact.rs (line 60)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_charset(CharSet::Unicode)
        .with_colors(ColorChoice::Always)
        .with_style(DisplayStyle::Compact);

    builder.print(&report)
}
More examples
Hide additional examples
examples/comfortable.rs (line 60)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_charset(CharSet::Unicode)
        .with_colors(ColorChoice::Always)
        .with_style(DisplayStyle::Comfortable);

    builder.print(&report)
}
source

pub fn print(&self, reportable: &dyn Reportable) -> Result<(), Error>

Print the report to stdout.

Examples found in repository?
examples/cross_file.rs (line 60)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
More examples
Hide additional examples
examples/compact.rs (line 62)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_charset(CharSet::Unicode)
        .with_colors(ColorChoice::Always)
        .with_style(DisplayStyle::Compact);

    builder.print(&report)
}
examples/comfortable.rs (line 62)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_charset(CharSet::Unicode)
        .with_colors(ColorChoice::Always)
        .with_style(DisplayStyle::Comfortable);

    builder.print(&report)
}
examples/simple.rs (line 52)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
fn main() -> Result<(), Error> {
    let origin = "example.ara";
    let code = r#"
$b = match $a {
    1 => 2,
    2 => 3,
    default => "string",
};
"#;

    let map = SourceMap::new(vec![Source::new(SourceKind::Script, origin, code)]);

    let report = Report::new()
        .with_issue(
            Issue::error("E0417", "`match` arms have incompatible types")
                .with_source(origin, 6, 67)
                .with_annotation(
                    Annotation::secondary(origin, 26, 27)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(origin, 38, 39)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(origin, 56, 64)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0417`"),
        )
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
examples/collection.rs (line 83)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
fn main() -> Result<(), Error> {
    let first_origin = "example.ara";
    let first_code = r#"
$b = match $a {
    1 => 2,
    2 => 3,
    default => "string",
};
"#;

    let second_origin = "example-2.ara";
    let second_code = r#"
function foo(Bar&float) {}
"#;

    let map = SourceMap::new(vec![
        Source::new(SourceKind::Script, first_origin, first_code),
        Source::new(SourceKind::Script, second_origin, second_code),
    ]);

    let first_report = Report::new()
        .with_issue(
            Issue::error("E0417", "`match` arms have incompatible types")
                .with_source(first_origin, 6, 67)
                .with_annotation(
                    Annotation::secondary(first_origin, 26, 27)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(first_origin, 38, 39)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(first_origin, 56, 64)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0417`"),
        )
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let second_report = Report::new()
        .with_issue(
            Issue::error(
                "P0015",
                "scalar type `float` cannot be used in an intersection",
            )
            .with_source(second_origin, 18, 23)
            .with_annotation(
                Annotation::secondary(second_origin, 17, 19)
                    .with_message("scalar type `float` cannot be used in an intersection"),
            )
            .with_note("a scalar type is either `int`, `float`, `string`, or `bool`.")
            .with_note("try using a different type for the intersection."),
        )
        .with_issue(Issue::bug("B0001", "failed to read the file"))
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let reports: ReportCollection = vec![&first_report, &second_report];

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&reports)
}
examples/example.rs (line 106)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![Source::inline(
        SourceKind::Script,
        r#"
function main(): int|string {
    $a = 1;
    $b = 2;

    $c = $a + $b;

    $b = match ($a) {
        1 => 2,
        2 => 3,
        default => "string",
    };

    return $c + $b;
}
"#,
    )]);

    let report = Report::new()
        .with_issue(
            Issue::error("E123", "some error here")
                .with_source(DEFAULT_NAME, 35, 41)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::warning("W123", "some warning here")
                .with_source(DEFAULT_NAME, 29, 187)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::warning("W124", "some warning here")
                .with_source(DEFAULT_NAME, 29, 187)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::note("N123", "some note here")
                .with_source(DEFAULT_NAME, 84, 163)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 121, 128)
                        .with_message("another annotation"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::help("H123", "some help here")
                .with_source(DEFAULT_NAME, 137, 147)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
                )
                .with_note("this is a note"),
        )
        .with_issue(
            Issue::bug("E123", "`match` arms have incompatible types")
                .with_source(DEFAULT_NAME, 84, 163)
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 110, 111)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 126, 127)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(DEFAULT_NAME, 148, 156)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0308`"),
        )
        .with_footer(ReportFooter::new("this is a report footer message"));

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}
source

pub fn eprint(&self, reportable: &dyn Reportable) -> Result<(), Error>

Print the report to stderr.

source

pub fn as_string(&self, reportable: &dyn Reportable) -> Result<String, Error>

Get the report as a string.

source

pub fn write<T: WriteColor>(
    &self,
    w: T,
    reportable: &dyn Reportable
) -> Result<(), Error>

Write the report to the given writer.

Trait Implementations§

source§

impl<'a> Clone for ReportBuilder<'a>

source§

fn clone(&self) -> ReportBuilder<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for ReportBuilder<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for ReportBuilder<'a>

§

impl<'a> Send for ReportBuilder<'a>

§

impl<'a> Sync for ReportBuilder<'a>

§

impl<'a> Unpin for ReportBuilder<'a>

§

impl<'a> UnwindSafe for ReportBuilder<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere
    T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere
    T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.