iocaine 3.0.0

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

use anyhow::Result;
use fakejpeg::{ImageGenerator, Options, Template};
use rand::RngCore;
use std::fs::File;
use std::sync::Arc;

#[derive(Clone)]
pub struct FakeMoustache(Arc<Template>);

impl FakeMoustache {
    pub fn new<S: AsRef<str>>(template_path: S) -> Result<Self> {
        let file = File::open(template_path.as_ref())?;
        let template: Template = ciborium::from_reader(file)?;
        Ok(Self(Arc::from(template)))
    }

    pub fn generate<R: RngCore, S: AsRef<str>>(
        &self,
        mut rng: R,
        comment: Option<S>,
    ) -> Result<Vec<u8>> {
        let generator = ImageGenerator::from(&*self.0);
        let mut options = Options::default();
        if let Some(comment) = comment {
            options.comment(comment.as_ref());
        }
        Ok(generator.emit(options.build(&mut rng))?)
    }
}