Include_str! and paths... curious about behavior

I have a small project with this layout:


In one of the src files I have lines like this: pub const ICON: &str = include_str!("../images/amp.svg");.
And this works fine on Linux and Windows and with cargo publish.

But if I use a different subdir, e.g. amp/data/help.html, although it works fine on Linux and Windows, cargo publish says it can't find the file. I then tried moving help.html into amp/images but that didn't work either.

The help.html file is tiny so I just include it as an actual rust string in a .rs file.

But I am curious as to why a path of ../images works only for .svg files (and presumably other image formats) but not for .html files, and why I can't make include_str! work with non-images and a non-images dir?

If the file isn't found when you're running cargo publish, that's probably due to the inclusion and exclusion rules not including that file in the to-be-published copy of the package. It sounds likely that you might have set up images/ and data/ differently there either in your Cargo.toml or a .gitignore file.

Thank you! I'd completely forgotten about the Cargo.toml include line. That's fixed it.

It depends on your application, but you normally never need to use the include and exclude fields in Cargo.toml. It's normally enough to rely on .gitignore.