From 12f7f36efab6499eb139e5f8993de4ca2b166f20 Mon Sep 17 00:00:00 2001 From: Лач Date: Sun, 28 Jun 2020 12:34:15 +0000 Subject: [PATCH] feat(evaluator): import resolver as_any method --- --- a/crates/jrsonnet-evaluator/src/import.rs +++ b/crates/jrsonnet-evaluator/src/import.rs @@ -6,11 +6,12 @@ use fs::File; use std::fs; use std::io::Read; -use std::{cell::RefCell, collections::HashMap, path::PathBuf, rc::Rc}; +use std::{any::Any, cell::RefCell, collections::HashMap, path::PathBuf, rc::Rc}; pub trait ImportResolver { fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result>; fn load_file_contents(&self, resolved: &PathBuf) -> Result>; + unsafe fn as_any(&self) -> &dyn Any; } pub struct DummyImportResolver; @@ -22,6 +23,9 @@ // Can be only caused by library direct consumer, not by supplied jsonnet panic!("dummy resolver can't load any file") } + unsafe fn as_any(&self) -> &dyn Any { + panic!("this resolver can't be used as any") + } } impl Default for Box { fn default() -> Self { @@ -57,6 +61,9 @@ .map_err(|_e| create_error(Error::ImportBadFileUtf8(id.clone())))?; Ok(out.into()) } + unsafe fn as_any(&self) -> &dyn Any { + panic!("this resolver can't be used as any") + } } type ResolutionData = (PathBuf, PathBuf); @@ -80,4 +87,7 @@ .or_insert_with(|| self.inner.load_file_contents(resolved)) .clone() } + unsafe fn as_any(&self) -> &dyn Any { + panic!("this resolver can't be used as any") + } } -- gitstuff