iocaine 2.2.0

The deadliest poison known to AI
Documentation
// SPDX-FileCopyrightText: 2025 Gergely Nagy
// SPDX-FileContributor: Gergely Nagy
//
// SPDX-License-Identifier: MIT

use roto::{Runtime, roto_static_method};
use semver::{Version, VersionReq};
use std::sync::Arc;

use crate::{app::VERSION, means_of_production::Error};

#[derive(Debug, Clone)]
pub struct IocaineVersion;

pub fn register_version(runtime: &mut Runtime) -> Result<(), Error> {
    runtime.register_clone_type_with_name::<IocaineVersion>(
        "IocaineVersion",
        "iocaine's version number",
    )?;

    #[roto_static_method(runtime, IocaineVersion)]
    fn matches(requirement: Arc<str>) -> bool {
        let version = match Version::parse(VERSION) {
            Ok(v) => v,
            Err(e) => {
                tracing::error!(
                    { version = VERSION },
                    "Unable to parse iocaine version: {e}"
                );
                return false;
            }
        };

        VersionReq::parse(&requirement).map_or_else(
            |e| {
                tracing::error!(
                    { requirement = requirement.to_string() },
                    "Unable to parse semantic version requirement: {e}"
                );
                false
            },
            |req| req.matches(&version),
        )
    }

    Ok(())
}