API improvement for grass::from_path
Hey, once again I am very pleased with how far this project has come! Keep up the good work.
I wanted to suggest an API improvement to grass::from_path. There are definitely a few ways to do this, however in a use case of mine, I am dealing with a potentially cross-platform FS path. So, either a &Path or an AsRef<Path> might be a nice improvement here. Currently, the parameter just needs to be a &str. Which is obviously doable, but I think in many cases, the suggestion I'm making here will be an ergonomics improvement.
I should have time to pop a quick PR for this later today, but I at least wanted to open this up for some discussion.
In fact, grass did originally have this API. A dependency we use to track files/spans uses String, so it was easiest to just switch to only using String as well. In practice, Sass files must be valid utf8, so the only place in which a path may theoretically be invalid utf8 is when passed to from_path.
The solutions that I see are
- Allow
AsRef<Path>, panicking or returning anErrwhen the path is not valid utf8 and making more explicit in the docs thatgrassdoes not accept invalid utf8 paths - Send a PR to codemap to allow non-utf8 paths for file names
I suppose changing &str to AsRef<Path> wouldn't necessarily be a breaking change, but I think it may still be a good idea to release this as one.
If you'd like to implement the former of the two in a PR that would be great!
This has been implemented in 31bbe8f and will be released as a new minor version to crates.io at some point this week.