git.delta.rocks / jrsonnet / refs/commits / f9d3f7169272

difftreelog

feat use explicit `impl Future`s in `AsyncImportResolver`

Petr Portnov2023-10-29parent: #f519684.patch.diff
in: master

1 file changed

modifiedcrates/jrsonnet-evaluator/src/async_import.rsdiffbeforeafterboth
1use std::{cell::RefCell, path::Path};1use std::{cell::RefCell, future::Future, path::Path};
22
3use jrsonnet_gcmodule::Trace;3use jrsonnet_gcmodule::Trace;
4use jrsonnet_interner::IStr;4use jrsonnet_interner::IStr;
217 }217 }
218}218}
219219
220// we don't care about `Send` bound
221#[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 correspond
225 /// 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 panic
230 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 things
235 async fn resolve(&self, path: &Path) -> Result<SourcePath, Self::Error>;240 fn resolve(&self, path: &Path) -> impl Future<Output = Result<SourcePath, Self::Error>>;
236241
237 /// Load resolved file242 /// Load resolved file
243 /// This should only be called with value returned
238 /// 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}
242252
243#[derive(Trace)]253#[derive(Trace)]