identity_credential/sd_jwt_vc/
resolver.rs

1// Copyright 2020-2024 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use async_trait::async_trait;
5use thiserror::Error;
6
7pub(crate) type Result<T> = std::result::Result<T, Error>;
8
9/// [`Resolver`]'s errors.
10#[derive(Debug, Error)]
11pub enum Error {
12  /// The queried item doesn't exist.
13  #[error("The requested item \"{0}\" was not found.")]
14  NotFound(String),
15  /// Failed to parse input.
16  #[error("Failed to parse the provided input into a resolvable type: {0}")]
17  ParsingFailure(#[source] anyhow::Error),
18  /// Generic error.
19  #[error(transparent)]
20  Generic(#[from] anyhow::Error),
21}
22
23/// A type capable of asynchronously producing values of type `T` from inputs of type `I`.
24#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
25#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
26pub trait Resolver<I: Sync, T> {
27  /// Fetch the resource of type [`Resolver::Target`] using `input`.
28  async fn resolve(&self, input: &I) -> Result<T>;
29}