From 26d996fbf93ca5ec0f2575c004ead557260eea5f Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 20 Oct 2024 00:53:49 +0200 Subject: [PATCH] chore: moved fn below --- src/model/endpoint.rs | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/model/endpoint.rs b/src/model/endpoint.rs index 963afba..af08953 100644 --- a/src/model/endpoint.rs +++ b/src/model/endpoint.rs @@ -28,31 +28,6 @@ pub struct Endpoint { pub extract: Option>, } -fn replace_recursive(element: toml::Value, from: &str, to: &str) -> toml::Value { - match element { - toml::Value::Float(x) => toml::Value::Float(x), - toml::Value::Integer(x) => toml::Value::Integer(x), - toml::Value::Boolean(x) => toml::Value::Boolean(x), - toml::Value::Datetime(x) => toml::Value::Datetime(x), - toml::Value::String(x) => toml::Value::String(x.replace(from, to)), - toml::Value::Array(x) => toml::Value::Array( - x.into_iter().map(|x| replace_recursive(x, from, to)).collect() - ), - toml::Value::Table(map) => { - let mut out = toml::map::Map::new(); - for (k, v) in map { - let new_v = replace_recursive(v.clone(), from, to); - if k.contains(from) { - out.insert(k.replace(from, to), new_v); - } else { - out.insert(k.to_string(), new_v); - } - } - toml::Value::Table(out) - }, - } -} - impl Endpoint { pub fn fill(mut self, env: &toml::Table) -> Self { let mut vars: HashMap = HashMap::default(); @@ -183,6 +158,31 @@ impl Endpoint { } } +fn replace_recursive(element: toml::Value, from: &str, to: &str) -> toml::Value { + match element { + toml::Value::Float(x) => toml::Value::Float(x), + toml::Value::Integer(x) => toml::Value::Integer(x), + toml::Value::Boolean(x) => toml::Value::Boolean(x), + toml::Value::Datetime(x) => toml::Value::Datetime(x), + toml::Value::String(x) => toml::Value::String(x.replace(from, to)), + toml::Value::Array(x) => toml::Value::Array( + x.into_iter().map(|x| replace_recursive(x, from, to)).collect() + ), + toml::Value::Table(map) => { + let mut out = toml::map::Map::new(); + for (k, v) in map { + let new_v = replace_recursive(v.clone(), from, to); + if k.contains(from) { + out.insert(k.replace(from, to), new_v); + } else { + out.insert(k.to_string(), new_v); + } + } + toml::Value::Table(out) + }, + } +} + async fn format_body(res: reqwest::Response) -> Result { match res.headers().get("Content-Type") { None => Ok(res.text().await? + "\n"),