memlink_runtime/resolver/
mod.rs1pub mod chain;
4pub mod local;
5
6use std::path::{Path, PathBuf};
7
8use crate::error::{Error, Result};
9
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum ModuleRef {
12 LocalPath(PathBuf),
13}
14
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub enum ArtifactHandle {
17 Local(PathBuf),
18}
19
20impl ArtifactHandle {
21 pub fn path(&self) -> &Path {
22 match self {
23 ArtifactHandle::Local(path) => path,
24 }
25 }
26}
27
28pub trait ModuleResolver: Send + Sync {
29 fn resolve(&self, reference: ModuleRef) -> Result<ArtifactHandle>;
30}
31
32impl ModuleRef {
33 pub fn parse(spec: &str) -> Result<Self> {
34 if spec.contains('@') && !spec.contains('/') && !spec.contains('\\') && !spec.starts_with('.') {
35 return Err(Error::RegistryNotImplemented);
36 }
37
38 let is_path = spec.contains('/')
39 || spec.contains('\\')
40 || spec.starts_with('.')
41 || spec.starts_with("..");
42
43 if !is_path {
44 return Err(Error::UnsupportedReference);
45 }
46
47 Ok(ModuleRef::LocalPath(PathBuf::from(spec)))
48 }
49}