22 lines
816 B
Python
22 lines
816 B
Python
import re
|
|
|
|
with open("server/src/state.rs", "r", encoding="utf-8") as f:
|
|
content = f.read()
|
|
|
|
# Add git_branch and namespace to Entity initialization
|
|
content = content.replace("observations: Vec::new(),", "observations: Vec::new(),\n namespace: src_ent.namespace.clone(),\n git_branch: src_ent.git_branch.clone(),")
|
|
|
|
# Add unique_items back
|
|
unique_items_code = """
|
|
pub fn unique_items<T: Eq + std::hash::Hash + Clone>(input: Vec<T>) -> Vec<T> {
|
|
let mut keys = std::collections::HashSet::new();
|
|
input.into_iter().filter(|entry| keys.insert(entry.clone())).collect()
|
|
}
|
|
"""
|
|
|
|
content = content.replace("impl MemoryState {\n", "impl MemoryState {\n" + unique_items_code)
|
|
|
|
with open("server/src/state.rs", "w", encoding="utf-8") as f:
|
|
f.write(content)
|
|
|