use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::fs; use std::path::Path; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DatasetConfig { pub dataset_name: String, pub description: String, pub version: String, pub license: String, pub tags: Vec, pub task_categories: Vec, pub language: Vec, pub size_categories: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DatasetInfo { pub description: String, pub citation: String, pub license: String, pub features: HashMap, pub splits: HashMap, pub download_size: u64, pub dataset_size: u64, pub config_name: String, pub dataset_name: String, pub version: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct FeatureInfo { pub dtype: String, pub description: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SplitInfo { pub name: String, pub num_bytes: u64, pub num_examples: u64, } pub struct MycelialHFConverter { base_path: String, } impl MycelialHFConverter { pub fn new(base_path: &str) -> Self { Self { base_path: base_path.to_string(), } } pub fn create_hf_dataset(&self) -> Result<(), Box> { println!("🍄 Converting mycelial dataset to Hugging Face format..."); self.create_dataset_config()?; self.create_dataset_info()?; self.update_readme()?; println!("✅ Hugging Face dataset structure created!"); Ok(()) } fn create_dataset_config(&self) -> Result<(), Box> { let config = DatasetConfig { dataset_name: "rustc-usage-patterns".to_string(), description: "Comprehensive Rust compiler usage patterns from 864 crates and rustc internals".to_string(), version: "1.0.0".to_string(), license: "MIT".to_string(), tags: vec![ "rust".to_string(), "compiler".to_string(), "ast".to_string(), "usage-patterns".to_string(), "code-analysis".to_string(), ], task_categories: vec![ "other".to_string(), ], language: vec!["en".to_string()], size_categories: "100M Result<(), Box> { let mut features = HashMap::new(); features.insert("crate_name".to_string(), FeatureInfo { dtype: "string".to_string(), description: "Name of the analyzed crate".to_string(), }); features.insert("usage_data".to_string(), FeatureInfo { dtype: "string".to_string(), description: "JSON usage patterns and AST data".to_string(), }); let mut splits = HashMap::new(); splits.insert("train".to_string(), SplitInfo { name: "train".to_string(), num_bytes: 118_000_000, // ~113MB num_examples: 9137, }); let info = DatasetInfo { description: "The most comprehensive Rust compiler usage pattern dataset ever assembled. Contains AST traversal data, type-aware literal tracking, and real-world compilation patterns from 864 crates plus rustc internals.".to_string(), citation: "@misc{mycelial-rust-usage-2026,\n title={Mycelial Rust Usage Patterns Dataset},\n author={Introspector Collective},\n year={2026},\n url={https://huggingface.co/datasets/introspector/rustc-usage}\n}".to_string(), license: "MIT".to_string(), features, splits, download_size: 118_000_000, dataset_size: 118_000_000, config_name: "default".to_string(), dataset_name: "rustc-usage-patterns".to_string(), version: "1.0.0".to_string(), }; let info_json = serde_json::to_string_pretty(&info)?; fs::write( Path::new(&self.base_path).join("dataset_info.json"), info_json, )?; Ok(()) } fn update_readme(&self) -> Result<(), Box> { let readme_content = r#"--- dataset_info: config_name: default features: - name: crate_name dtype: string - name: usage_data dtype: string splits: - name: train num_bytes: 118000000 num_examples: 9137 download_size: 118000000 dataset_size: 118000000 configs: - config_name: default data_files: - split: train path: "test_usage_data/*.json" task_categories: - other language: - en tags: - rust - compiler - ast - usage-patterns - code-analysis size_categories: - 100M