use crate::loader::{Loader, LoadingResult};
use jsonld_syntax::native_stack::Recursion;
use rdfx::vocabulary::IriVocabularyMut;
use std::{future::Future, hash::Hash};
pub trait Dereference: Loader {
fn dereference<V>(&self, vocabulary: &mut V, url: V::Iri) -> impl Future<Output = LoadingResult<V::Iri, Self::Error>>
where
V: IriVocabularyMut,
V::Iri: Clone + Eq + Hash;
}
impl<L: Loader + ?Sized> Dereference for L {
fn dereference<V>(&self, vocabulary: &mut V, url: V::Iri) -> impl Future<Output = LoadingResult<V::Iri, Self::Error>>
where
V: IriVocabularyMut,
V::Iri: Clone + Eq + Hash,
{
Recursion::new(async move {
#[allow(clippy::expect_used)]
let lexical_url = vocabulary.iri(&url).expect("`url` does not resolve in the given vocabulary");
#[expect(clippy::disallowed_methods, reason = "the one guarded invocation of a loader every algorithm goes through")]
let document = self.load(lexical_url).await?;
Ok(document.map_iris(|i| vocabulary.insert_owned(i)))
})
}
}