Retrieve a stylesheet from the local filesystem. # Errors Any filesystem-related error.
(&self, path: &str)
| 52 | /// |
| 53 | /// Any filesystem-related error. |
| 54 | fn retrieve_from_path(&self, path: &str) -> Result<String> { |
| 55 | let path = path.trim_start_matches("file://"); |
| 56 | std::fs::read_to_string(path).map_err(|error| match error.kind() { |
| 57 | ErrorKind::NotFound => InlineError::MissingStyleSheet { |
| 58 | path: path.to_string(), |
| 59 | }, |
| 60 | #[cfg(target_family = "wasm")] |
| 61 | ErrorKind::Unsupported => self.unsupported(&format!( |
| 62 | "Loading local files is not supported on WASM: {path}" |
| 63 | )), |
| 64 | _ => InlineError::IO(error), |
| 65 | }) |
| 66 | } |
| 67 | /// Return the "Unsupported" kind of error. |
| 68 | fn unsupported(&self, reason: &str) -> InlineError { |
| 69 | std::io::Error::new(ErrorKind::Unsupported, reason).into() |
no test coverage detected