<commit_before>//! This is an implementation of variadic templates using recursive generics.
//! It functions something like a TypeMap, but the optimizer should make getting
//! and adding values much faster.

use std::any::{Any, TypeId};
use std::mem;

/// Something that 
pub trait RecursiveVariadic {
    // would be nice to have a 
    // type Data<T> = T 
    fn get<N: Any>(&self) -> Option<&N>;
    fn get_mut<N: Any>(&mut self) -> Option<&mut N>;
    fn and<N: Any>(self, val: N) -> Entry<N, Self> where Self: Sized {
        Entry {
            data: val,
            parent: self,
        }
    }
}

pub type Empty = ();
impl RecursiveVariadic for Empty {
    fn get<N: Any>(&self) -> Option<&N> { None }
    fn get_mut<N: Any>(&mut self) -> Option<&mut N> { None }
}

pub struct Entry<T, R> {<commit_msg>Improved docs<commit_after>//! This is an implementation of variadic templates using recursive generics.
//! It functions something like a TypeMap, but the optimizer should make getting
//! and adding values much faster.

use std::any::{Any, TypeId};
use std::mem;

/// The building block trait for recursive variadics.
pub trait RecursiveVariadic {
    /// Try to get the field of type N.
    fn get<N: Any>(&self) -> Option<&N>;
    /// Try to get the field of type N mutably.
    fn get_mut<N: Any>(&mut self) -> Option<&mut N>;
    /// Add a field of type N to this.
    fn and<N: Any>(self, val: N) -> Entry<N, Self> where Self: Sized {
        Entry {
            data: val,
            parent: self,
        }
    }
}

/// The base case for recursive variadics: no fields.
pub type Empty = ();
impl RecursiveVariadic for Empty {
    fn get<N: Any>(&self) -> Option<&N> { None }
    fn get_mut<N: Any>(&mut self) -> Option<&mut N> { None }
}

/// Wraps some field data and a parent, which is either another Entry or Empty
pub struct Entry<T, R> {
{'fraction_non_alphanumeric': 0.13551151580074985, 'fraction_numerical': 0.0, 'mean_word_length': 2.7211155378486054, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2671194', 'n_tokens_mistral': 621, 'n_tokens_neox': 597, 'n_words': 234}