use core::fmt;
use std::path::Path;
use crate::host::capabilities::LeanCapabilities;
use crate::host::lake::LakeProject;
use lean_rs::LeanRuntime;
use lean_rs::error::LeanResult;
use lean_rs::module::LeanLibrary;
pub struct LeanHost<'lean> {
runtime: &'lean LeanRuntime,
project: LakeProject,
}
impl fmt::Debug for LeanHost<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("LeanHost").finish_non_exhaustive()
}
}
impl<'lean> LeanHost<'lean> {
pub fn from_lake_project(runtime: &'lean LeanRuntime, path: impl AsRef<Path>) -> LeanResult<Self> {
let project = LakeProject::new(path)?;
Ok(Self { runtime, project })
}
pub fn load_capabilities<'h>(&'h self, package: &str, lib_name: &str) -> LeanResult<LeanCapabilities<'lean, 'h>> {
let dylib_path = self.project.capability_dylib(package, lib_name);
let library = LeanLibrary::open(self.runtime, &dylib_path)?;
LeanCapabilities::new(self, library, package, lib_name)
}
pub(crate) fn runtime(&self) -> &'lean LeanRuntime {
self.runtime
}
pub(crate) fn project(&self) -> &LakeProject {
&self.project
}
}