sing/src/lib.rs

71 lines
1.6 KiB
Rust
Raw Normal View History

use core::fmt::Debug;
2022-03-02 19:13:31 +01:00
use proc_macro2::TokenStream;
use serde::{Serialize, Deserialize};
use serde_wrapper::TokenStreamWrapper;
mod serde_wrapper;
#[derive(Debug, Clone, Serialize, Deserialize)]
struct TraitProfile{
//functions: HashMap<String, FunctionProfile>,
functions: Vec<TokenStreamWrapper>,
}
2022-03-02 19:13:31 +01:00
impl TraitProfile{
pub fn new(streams: Vec<TokenStream>) -> Self {
let mut inner = vec!();
for stream in streams {
inner.push(TokenStreamWrapper::new(stream));
}
Self{
functions: inner
}
}
}
#[derive(Debug, Clone)]
enum DeduplicatedFunctionProfile {
Single(String, TokenStreamWrapper),
Multiple(Vec<String>, TokenStreamWrapper),
}
/*impl<T> Evaluator<T> {
fn deduplicate_functions(&self) -> Self<T> {
let mut self = self.clone();
let mut functions: HashMap<String, DeduplicatedFunctionProfile>;
for (t_name, t_profile) in self.traits {
for (fun_name, fun_profile) in t_profile.functions {
if !functions.contains_key(fun_name) {
self.functions.insert(fun_name, DeduplicatedFunctionProfile::Single(t_name, fun_profile))
} else {
let other = self.functions.remove(fun_name).unwrap();
let traits: Vec<String>;
match other {
DeduplicatedFunctionProfile::Single(t, _) => traits = vec!(t),
DeduplicatedFunctionProfile::Multiple(ts, _) => traits = ts,
}
self.functions.insert(fun_name, DeduplicatedFunctionProfile::Multiple(traits, fun_profile))
}
}
}
}
}
*/
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}