From 2cd9e006e0b23ad37d7dd95fa633765a8a61fd91 Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Fri, 31 Jan 2025 22:35:42 +0530 Subject: [PATCH] minor: return &str instead of String --- fastn-core/src/library2022/processor/http.rs | 10 +++++----- ftd-ast/src/component.rs | 4 ++-- ftd-ast/src/kind.rs | 8 ++++---- ftd/src/interpreter/things/value.rs | 17 +++++++++-------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/fastn-core/src/library2022/processor/http.rs b/fastn-core/src/library2022/processor/http.rs index c4761d370..859254cc1 100644 --- a/fastn-core/src/library2022/processor/http.rs +++ b/fastn-core/src/library2022/processor/http.rs @@ -93,7 +93,7 @@ pub async fn process( // After resolve headers: id:1234(value of $query.id) if value.starts_with('$') { if let Some(value) = doc - .get_value(header.line_number, value.as_str())? + .get_value(header.line_number, value)? .to_json_string(doc, true)? { if let Some(key) = fastn_core::http::get_header_key(header.key.as_str()) { @@ -109,24 +109,24 @@ pub async fn process( } } else { if let Some(key) = fastn_core::http::get_header_key(header.key.as_str()) { - conf.insert(key.to_string(), value); + conf.insert(key.to_string(), value.to_string()); continue; } if method.as_str().eq("post") { body.push(format!( "\"{}\": \"{}\"", header.key, - fastn_core::utils::escape_string(value.as_str()) + fastn_core::utils::escape_string(value) )); continue; } url.query_pairs_mut() - .append_pair(header.key.as_str(), value.as_str()); + .append_pair(header.key.as_str(), value); } } if !req_config.config.test_command_running { - println!("calling `http` processor with url: {}", &url); + println!("calling `http` processor with url: {url}"); } let resp = if url.scheme() == "wasm+proxy" { diff --git a/ftd-ast/src/component.rs b/ftd-ast/src/component.rs index d54085263..756ee8f4c 100644 --- a/ftd-ast/src/component.rs +++ b/ftd-ast/src/component.rs @@ -534,7 +534,7 @@ impl Loop { let is_for_loop = loop_header.key.eq(ftd_ast::utils::FOR); let (alias, on, loop_counter_alias) = Self::get_loop_parameters( - loop_statement.as_str(), + loop_statement, is_for_loop, doc_id, loop_header.line_number, @@ -673,7 +673,7 @@ impl Event { Ok(Some(Event::new( event_name.as_str(), - action.as_str(), + action, header.line_number, ))) } diff --git a/ftd-ast/src/kind.rs b/ftd-ast/src/kind.rs index 87606fb89..7308487f5 100644 --- a/ftd-ast/src/kind.rs +++ b/ftd-ast/src/kind.rs @@ -242,7 +242,7 @@ impl HeaderValues { if header.value.is_null() { Ok(None) } else { - Ok(Some(header.value.string(doc_id)?)) + Ok(Some(header.value.string(doc_id)?.to_string())) } } else { Ok(None) @@ -330,10 +330,10 @@ impl VariableValue { name } - pub fn string(&self, doc_id: &str) -> ftd_ast::Result { + pub fn string(&self, doc_id: &str) -> ftd_ast::Result<&str> { match self { - VariableValue::String { value, .. } => Ok(value.to_string()), - VariableValue::Constant { value, .. } => Ok(value.to_string()), + VariableValue::String { value, .. } => Ok(value), + VariableValue::Constant { value, .. } => Ok(value), t => ftd_ast::parse_error( format!("Expect Variable value string, found: `{:?}`", t), doc_id, diff --git a/ftd/src/interpreter/things/value.rs b/ftd/src/interpreter/things/value.rs index 60a23534e..29d479ef5 100644 --- a/ftd/src/interpreter/things/value.rs +++ b/ftd/src/interpreter/things/value.rs @@ -198,26 +198,27 @@ impl PropertyValueExt for fastn_resolved::PropertyValue { loop_object_name_and_kind: &Option<(String, fastn_resolved::Argument, Option)>, ) -> ftd::interpreter::Result> { - if let Some(reference) = - try_ok_state!(fastn_resolved::PropertyValue::reference_from_ast_value( + dbg!(&value); + if let Some(reference) = try_ok_state!(dbg!( + fastn_resolved::PropertyValue::reference_from_ast_value( value.clone(), doc, is_mutable, expected_kind, definition_name_with_arguments, loop_object_name_and_kind, - )?) - { + ) + )?) { Ok(ftd::interpreter::StateWithThing::new_thing(reference)) } else { - fastn_resolved::PropertyValue::value_from_ast_value( + dbg!(fastn_resolved::PropertyValue::value_from_ast_value( value, doc, is_mutable, expected_kind, definition_name_with_arguments, loop_object_name_and_kind, - ) + )) } } @@ -675,7 +676,7 @@ impl PropertyValueExt for fastn_resolved::PropertyValue { fastn_resolved::Kind::String => ftd::interpreter::StateWithThing::new_thing( fastn_resolved::PropertyValue::Value { value: fastn_resolved::Value::String { - text: value.string(doc.name)?, + text: value.string(doc.name)?.to_string(), }, is_mutable, line_number: value.line_number(), @@ -881,7 +882,7 @@ impl PropertyValueExt for fastn_resolved::PropertyValue { fastn_resolved::Kind::Module => ftd::interpreter::StateWithThing::new_thing( fastn_resolved::PropertyValue::Value { value: fastn_resolved::Value::Module { - name: doc.resolve_module_name(value.string(doc.name)?.as_str()), + name: doc.resolve_module_name(value.string(doc.name)?), things: Default::default(), }, is_mutable,