Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileCache doesn't seem to work? #40

Open
trombonehero opened this issue Jul 12, 2022 · 4 comments
Open

FileCache doesn't seem to work? #40

trombonehero opened this issue Jul 12, 2022 · 4 comments
Labels
rewrite-todo Things to fix during the crate rewrite

Comments

@trombonehero
Copy link

I'm attempting to use ariadne::FileCache with Report::write (or print or eprint), but it doesn't seem to work for me.FileCache implements Cache<Path> but not Cache<PathBuf>, and as std::path::Path isn't sized, I can't pass a Path directly into Report::build or a Label. Using &Path in the following minimal example:

fn example() {
    use ariadne::*;

    let mut fc = FileCache::default();
    let path = std::path::PathBuf::from("example.txt").as_path();

    let mut builder = Report::build(ReportKind::Error, path, 10)
        .with_message("message")
        .with_label(Label::new((path, 10..20)).with_message("something bad"));

    builder.finish().eprint(fc).unwrap();
}

yields the following error:

error[E0277]: the trait bound `ariadne::FileCache: Cache<&Path>` is not satisfied
   --> src/parsing.rs:19:29
    |
19  |     builder.finish().eprint(fc).unwrap();
    |                      ------ ^^ the trait `Cache<&Path>` is not implemented for `ariadne::FileCache`
    |                      |
    |                      required by a bound introduced by this call
    |
    = help: the trait `Cache<Path>` is implemented for `ariadne::FileCache`
note: required by a bound in `ariadne::Report::<S>::eprint`
   --> /home/jon/.cargo/registry/src/github.com-1ecc6299db9ec823/ariadne-0.1.5/src/lib.rs:159:22
    |
159 |     pub fn eprint<C: Cache<S::SourceId>>(&self, cache: C) -> io::Result<()> {
    |                      ^^^^^^^^^^^^^^^^^^ required by this bound in `ariadne::Report::<S>::eprint`

For more information about this error, try `rustc --explain E0277`.

This is using ariadne 0.1.5.

Thanks!

@zesterer
Copy link
Owner

Argh, this is a frustrating oversight. For now, FnCache or a custom implementation of Cache should be sufficient. This API does require a pretty significant redesign though. I'll see whether I get the opportunity to do this over the next week!

@ggriffiniii
Copy link

I just stumbled on this same issue. If nothing else can FileCache be removed until a solution exists. It would have saved me a lot of time. As it was I saw what was clearly what I wanted and was banging my head against the wall trying to figure out how to get it to work, where I would have just used the FnCache if that was the only option.

@ggriffiniii
Copy link

Also it looks like FnCache doesn't work with Path/PathBuf either due to the requirement for Display that Path doesn't meet. So a custom implementation is required to work with Path/PathBuf. Not a big deal, just pointing it out.

@zesterer
Copy link
Owner

I'm slowly gearing up to a crate rewrite, so I'll add this to the list of things to fix when this happens. Thanks for the reminder!

@zesterer zesterer added the rewrite-todo Things to fix during the crate rewrite label Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rewrite-todo Things to fix during the crate rewrite
Projects
None yet
Development

No branches or pull requests

3 participants