refactor: apply zero-unwrap policy and optimize locks in store.rs and handlers
This commit is contained in:
1 parent
9f24e66d88
commit
8afbf97b11
33 files changed
+3127
-3207
No files matched your search
@@ -0,0 +1,14 @@
|
||||
import re
|
||||
|
||||
with open("server/src/handlers.rs", "r", encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
|
||||
pattern = r'"([a-zA-Z_]+)" => \{\s*(?:let req = parse_tool!\(args, id, ([a-zA-Z]+)\);\s*)?let data = serde_json::to_string\(&self\.state\.([a-zA-Z_]+)\.read\(\)\)\s*\.unwrap_or_else\(\|_\| "\[\]"\.to_string\(\)\);\s*Ok\(data\.to_string\(\)\)\s*\}'
|
||||
|
||||
def repl(m):
|
||||
return f'"{m.group(1)}" => {{\n let data = serde_json::to_string(&self.state.{m.group(3)}.read()).unwrap_or_else(|_| "[]".to_string());\n Ok(data)\n}},'
|
||||
|
||||
new_text = re.sub(pattern, repl, text)
|
||||
|
||||
with open("server/src/handlers.rs", "w", encoding="utf-8") as f:
|
||||
f.write(new_text)
|
||||
Reference in new issue
Block a user