Skip to content

Commit

Permalink
Merge pull request #138 from CertainLach/stable-async-traits
Browse files Browse the repository at this point in the history
build: use now-stable async traits
  • Loading branch information
CertainLach authored Oct 29, 2023
2 parents fd582d4 + 69bb25d commit e7e620b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/clippy_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: nightly-2023-10-28
components: clippy
override: true
- uses: actions-rs/clippy-check@v1
Expand Down
33 changes: 6 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ static_assertions = "1.1"
rustc-hash = "1.1"
bincode = "1.3"
annotate-snippets = "0.9.1"
async-trait = "0.1.60"
num-bigint = "0.4.3"
derivative = "2.2.0"
strsim = "0.10.0"
Expand All @@ -45,7 +44,7 @@ quote = "1.0"
syn = "2.0"
peg = "0.8.2"
drop_bomb = "0.1.5"
logos = "0.13.0"
logos = "0.12.0"
miette = "5.5.0"
rowan = "0.15"
text-size = "1.1"
Expand Down
4 changes: 1 addition & 3 deletions crates/jrsonnet-evaluator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ explaining-traces = ["annotate-snippets"]
# Allows library authors to throw custom errors
anyhow-error = ["anyhow"]
# Adds ability to build import closure in async
async-import = ["async-trait"]
async-import = []

# Allows to preserve field order in objects
exp-preserve-order = []
Expand Down Expand Up @@ -54,8 +54,6 @@ anyhow = { workspace = true, optional = true }
bincode = { workspace = true, optional = true }
# Explaining traces
annotate-snippets = { workspace = true, features = ["color"], optional = true }
# Async imports
async-trait = { workspace = true, optional = true }
# Bigint
num-bigint = { workspace = true, features = ["serde"], optional = true }
derivative.workspace = true
34 changes: 22 additions & 12 deletions crates/jrsonnet-evaluator/src/async_import.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{cell::RefCell, path::Path};
use std::{cell::RefCell, future::Future, path::Path};

use async_trait::async_trait;
use jrsonnet_gcmodule::Trace;
use jrsonnet_interner::IStr;
use jrsonnet_parser::{
Expand Down Expand Up @@ -218,26 +217,37 @@ pub fn find_imports(expr: &LocExpr, out: &mut FoundImports) {
}
}

#[async_trait(?Send)]
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<SourcePath, Self::Error>;
async fn resolve_from_default(&self, path: &str) -> Result<SourcePath, Self::Error> {
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<Output = Result<SourcePath, Self::Error>>;
fn resolve_from_default(
&self,
path: &str,
) -> impl Future<Output = Result<SourcePath, Self::Error>> {
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<SourcePath, Self::Error>;
fn resolve(&self, path: &Path) -> impl Future<Output = Result<SourcePath, Self::Error>>;

/// 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<Vec<u8>, 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<Output = Result<Vec<u8>, Self::Error>>;
}

#[derive(Trace)]
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
lib = pkgs.lib;
rust =
(pkgs.rustChannelOf {
date = "2023-08-02";
date = "2023-10-28";
channel = "nightly";
})
.default
Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "nightly-2023-10-28"
components = ["rustfmt", "clippy"]

0 comments on commit e7e620b

Please sign in to comment.