Function ariadne::sources

source ·
pub fn sources<Id, S, I>(iter: I) -> impl Cache<Id>where
    Id: Display + Hash + PartialEq + Eq + Clone + 'static,
    I: IntoIterator<Item = (Id, S)>,
    S: AsRef<str>,
Expand description

Create a Cache from a collection of ID/strings, where each corresponds to a Source.

Examples found in repository?
examples/multifile.rs (lines 29-32)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() {
    let mut colors = ColorGenerator::new();

    // Generate some colours for each of our elements
    let a = colors.next();
    let b = colors.next();
    let c = colors.next();

    Report::build(ReportKind::Error, "b.tao", 10)
        .with_code(3)
        .with_message(format!("Cannot add types Nat and Str"))
        .with_label(Label::new(("b.tao", 10..14))
            .with_message(format!("This is of type {}", "Nat".fg(a)))
            .with_color(a))
        .with_label(Label::new(("b.tao", 17..20))
            .with_message(format!("This is of type {}", "Str".fg(b)))
            .with_color(b))
        .with_label(Label::new(("b.tao", 15..16))
            .with_message(format!(" {} and {} undergo addition here", "Nat".fg(a), "Str".fg(b)))
            .with_color(c)
            .with_order(10))
        .with_label(Label::new(("a.tao", 4..8))
            .with_message(format!("Original definition of {} is here", "five".fg(a)))
            .with_color(a))
        .with_note(format!("{} is a number and can only be added to other numbers", "Nat".fg(a)))
        .finish()
        .print(sources(vec![
            ("a.tao", include_str!("a.tao")),
            ("b.tao", include_str!("b.tao")),
        ]))
        .unwrap();
}