dolang-ext-http-mock 0.1.0

HTTP mock server extension for the Do language.
use std::{
    error,
    fmt::{self, Debug, Display, Formatter},
};

use dolang::{
    compile::Compiler,
    extension,
    extension::{Extension, Version},
    runtime::vm::Builder,
};

use crate::{global::Global, mock};

/// HTTP mock server extension
pub struct Shell;

#[derive(Debug)]
pub enum Infallible {}

impl Display for Infallible {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        Debug::fmt(self, f)
    }
}

impl error::Error for Infallible {}

impl Extension for Shell {
    type Error = Infallible;
    const NAME: &str = "dolang-http-mock";
    const VERSION: Version = dolang::package_version!();
    const DESCRIPTION: &str = "Do HTTP Mock Server Extension";

    fn apply_compiler(&self, _compiler: &mut Compiler) -> Result<(), Infallible> {
        Ok(())
    }

    fn apply_vm<'v>(&self, builder: &mut Builder<'v>) -> Result<(), Infallible> {
        let global = Global::new(builder);
        let global = builder.register_state(global);
        mock::configure_vm(builder, global);
        Ok(())
    }
}

extension!(Shell);