mirror of
https://github.com/helix-editor/helix.git
synced 2025-04-02 02:17:44 +03:00
minor: Accept impl AsRef<Path>
in loader's runtime_file helper
This is purely for ergonomics: we should be able to pass strings for example crate::runtime_file(format!("namespace/{foo}/{bar}.txt")) (Note that this works on Windows, see the `Path` documentation.)
This commit is contained in:
parent
b7d735ffe6
commit
1dee64f7ec
2 changed files with 3 additions and 3 deletions
|
@ -592,6 +592,6 @@ fn mtime(path: &Path) -> Result<SystemTime> {
|
|||
/// Gives the contents of a file from a language's `runtime/queries/<lang>`
|
||||
/// directory
|
||||
pub fn load_runtime_file(language: &str, filename: &str) -> Result<String, std::io::Error> {
|
||||
let path = crate::runtime_file(&PathBuf::new().join("queries").join(language).join(filename));
|
||||
let path = crate::runtime_file(PathBuf::new().join("queries").join(language).join(filename));
|
||||
std::fs::read_to_string(path)
|
||||
}
|
||||
|
|
|
@ -107,8 +107,8 @@ fn find_runtime_file(rel_path: &Path) -> Option<PathBuf> {
|
|||
/// The valid runtime directories are searched in priority order and the first
|
||||
/// file found to exist is returned, otherwise the path to the final attempt
|
||||
/// that failed.
|
||||
pub fn runtime_file(rel_path: &Path) -> PathBuf {
|
||||
find_runtime_file(rel_path).unwrap_or_else(|| {
|
||||
pub fn runtime_file(rel_path: impl AsRef<Path>) -> PathBuf {
|
||||
find_runtime_file(rel_path.as_ref()).unwrap_or_else(|| {
|
||||
RUNTIME_DIRS
|
||||
.last()
|
||||
.map(|dir| dir.join(rel_path))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue