From 929f4d64fef8054cbaf34d556467a7d2b9d09b47 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 21 Jul 2021 12:27:40 +0200 Subject: Switch Loader from Option to io::Result --- src/loading/mod.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/loading/mod.rs') diff --git a/src/loading/mod.rs b/src/loading/mod.rs index 3be74428..64a65580 100644 --- a/src/loading/mod.rs +++ b/src/loading/mod.rs @@ -6,6 +6,7 @@ mod fs; #[cfg(feature = "fs")] pub use fs::*; +use std::io; use std::path::Path; use serde::{Deserialize, Serialize}; @@ -21,10 +22,13 @@ pub trait Loader { /// /// This should return the same id for all paths pointing to the same file /// and `None` if the file does not exist. - fn resolve_from(&self, base: FileId, path: &Path) -> Option; + fn resolve_from(&self, base: FileId, path: &Path) -> io::Result; /// Load a file by id. - fn load_file(&self, id: FileId) -> Option>; + /// + /// This must only be called with an `id` returned by a call to this + /// loader's `resolve_from` method. + fn load_file(&self, id: FileId) -> io::Result>; } /// A file id that can be [resolved](Loader::resolve_from) from a path. @@ -53,11 +57,11 @@ impl Loader for BlankLoader { &[] } - fn resolve_from(&self, _: FileId, _: &Path) -> Option { - None + fn resolve_from(&self, _: FileId, _: &Path) -> io::Result { + Err(io::ErrorKind::NotFound.into()) } - fn load_file(&self, _: FileId) -> Option> { - None + fn load_file(&self, _: FileId) -> io::Result> { + panic!("resolve_from never returns an id") } } -- cgit v1.2.3