artichoke_backend/extn/core/enumerator/
mod.rs

1use std::ffi::CStr;
2
3use crate::extn::prelude::*;
4
5const ENUMERATOR_CSTR: &CStr = c"Enumerator";
6static ENUMERATOR_RUBY_SOURCE: &[u8] = include_bytes!("enumerator.rb");
7static ENUMERATOR_LAZY_RUBY_SOURCE: &[u8] = include_bytes!("lazy.rb");
8
9pub fn init(interp: &mut Artichoke) -> InitializeResult<()> {
10    if interp.is_class_defined::<Enumerator>() {
11        return Ok(());
12    }
13
14    let spec = class::Spec::new("Enumerator", ENUMERATOR_CSTR, None, None)?;
15    interp.def_class::<Enumerator>(spec)?;
16    interp.eval(ENUMERATOR_RUBY_SOURCE)?;
17    interp.eval(ENUMERATOR_LAZY_RUBY_SOURCE)?;
18
19    Ok(())
20}
21
22#[derive(Debug, Clone, Copy)]
23pub struct Enumerator;