From f9d3f71692729f6d49f3f4eea6a3808516e72ecd Mon Sep 17 00:00:00 2001 From: Petr Portnov Date: Sun, 29 Oct 2023 18:26:00 +0000 Subject: [PATCH] feat: use explicit `impl Future`s in `AsyncImportResolver` --- --- a/crates/jrsonnet-evaluator/src/async_import.rs +++ b/crates/jrsonnet-evaluator/src/async_import.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, path::Path}; +use std::{cell::RefCell, future::Future, path::Path}; use jrsonnet_gcmodule::Trace; use jrsonnet_interner::IStr; @@ -217,27 +217,37 @@ } } -// we don't care about `Send` bound -#[allow(async_fn_in_trait)] pub trait AsyncImportResolver { type Error; /// Resolves file path, e.g. `(/home/user/manifests, b.libjsonnet)` can correspond /// both to `/home/user/manifests/b.libjsonnet` and to `/home/user/${vendor}/b.libjsonnet` /// where `${vendor}` is a library path. /// - /// `from` should only be returned from [`ImportResolver::resolve`], or from other defined file, any other value - /// may result in panic - async fn resolve_from(&self, from: &SourcePath, path: &str) -> Result; - async fn resolve_from_default(&self, path: &str) -> Result { - self.resolve_from(&SourcePath::default(), path).await + /// `from` should only be returned from [`ImportResolver::resolve`], + /// or from other defined file, any other value may result in panic + fn resolve_from( + &self, + from: &SourcePath, + path: &str, + ) -> impl Future>; + fn resolve_from_default( + &self, + path: &str, + ) -> impl Future> { + async { self.resolve_from(&SourcePath::default(), path).await } } /// Resolves absolute path, doesn't supports jpath and other fancy things - async fn resolve(&self, path: &Path) -> Result; + fn resolve(&self, path: &Path) -> impl Future>; /// Load resolved file - /// This should only be called with value returned from [`ImportResolver::resolve_file`]/[`ImportResolver::resolve`], - /// this cannot be resolved using associated type, as evaluator uses object instead of generic for [`ImportResolver`] - async fn load_file_contents(&self, resolved: &SourcePath) -> Result, Self::Error>; + /// This should only be called with value returned + /// from [`ImportResolver::resolve_file`]/[`ImportResolver::resolve`], + /// this cannot be resolved using associated type, + /// as the evaluator uses object instead of generic for [`ImportResolver`] + fn load_file_contents( + &self, + resolved: &SourcePath, + ) -> impl Future, Self::Error>>; } #[derive(Trace)] -- gitstuff