difftreelog
feat use explicit `impl Future`s in `AsyncImportResolver`
in: master
1 file changed
crates/jrsonnet-evaluator/src/async_import.rsdiffbeforeafterboth1use std::{cell::RefCell, path::Path};1use std::{cell::RefCell, future::Future, path::Path};223use jrsonnet_gcmodule::Trace;3use jrsonnet_gcmodule::Trace;4use jrsonnet_interner::IStr;4use jrsonnet_interner::IStr;217 }217 }218}218}219219220// we don't care about `Send` bound221#[allow(async_fn_in_trait)]222pub trait AsyncImportResolver {220pub trait AsyncImportResolver {223 type Error;221 type Error;224 /// Resolves file path, e.g. `(/home/user/manifests, b.libjsonnet)` can correspond222 /// Resolves file path, e.g. `(/home/user/manifests, b.libjsonnet)` can correspond225 /// both to `/home/user/manifests/b.libjsonnet` and to `/home/user/${vendor}/b.libjsonnet`223 /// both to `/home/user/manifests/b.libjsonnet` and to `/home/user/${vendor}/b.libjsonnet`226 /// where `${vendor}` is a library path.224 /// where `${vendor}` is a library path.227 ///225 ///228 /// `from` should only be returned from [`ImportResolver::resolve`], or from other defined file, any other value226 /// `from` should only be returned from [`ImportResolver::resolve`],229 /// may result in panic227 /// or from other defined file, any other value may result in panic230 async fn resolve_from(&self, from: &SourcePath, path: &str) -> Result<SourcePath, Self::Error>;228 fn resolve_from(229 &self,230 from: &SourcePath,231 path: &str,232 ) -> impl Future<Output = Result<SourcePath, Self::Error>>;231 async fn resolve_from_default(&self, path: &str) -> Result<SourcePath, Self::Error> {233 fn resolve_from_default(234 &self,235 path: &str,236 ) -> impl Future<Output = Result<SourcePath, Self::Error>> {232 self.resolve_from(&SourcePath::default(), path).await237 async { self.resolve_from(&SourcePath::default(), path).await }233 }238 }234 /// Resolves absolute path, doesn't supports jpath and other fancy things239 /// Resolves absolute path, doesn't supports jpath and other fancy things235 async fn resolve(&self, path: &Path) -> Result<SourcePath, Self::Error>;240 fn resolve(&self, path: &Path) -> impl Future<Output = Result<SourcePath, Self::Error>>;236241237 /// Load resolved file242 /// Load resolved file243 /// This should only be called with value returned238 /// This should only be called with value returned from [`ImportResolver::resolve_file`]/[`ImportResolver::resolve`],244 /// from [`ImportResolver::resolve_file`]/[`ImportResolver::resolve`],245 /// this cannot be resolved using associated type,239 /// this cannot be resolved using associated type, as evaluator uses object instead of generic for [`ImportResolver`]246 /// as the evaluator uses object instead of generic for [`ImportResolver`]240 async fn load_file_contents(&self, resolved: &SourcePath) -> Result<Vec<u8>, Self::Error>;247 fn load_file_contents(248 &self,249 resolved: &SourcePath,250 ) -> impl Future<Output = Result<Vec<u8>, Self::Error>>;241}251}242252243#[derive(Trace)]253#[derive(Trace)]