Skip to content

Commit

Permalink
minor: return &str instead of String
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Jan 31, 2025
1 parent cb020e1 commit 2cd9e00
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
10 changes: 5 additions & 5 deletions fastn-core/src/library2022/processor/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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" {
Expand Down
4 changes: 2 additions & 2 deletions ftd-ast/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -673,7 +673,7 @@ impl Event {

Ok(Some(Event::new(
event_name.as_str(),
action.as_str(),
action,
header.line_number,
)))
}
Expand Down
8 changes: 4 additions & 4 deletions ftd-ast/src/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -330,10 +330,10 @@ impl VariableValue {
name
}

pub fn string(&self, doc_id: &str) -> ftd_ast::Result<String> {
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,
Expand Down
17 changes: 9 additions & 8 deletions ftd/src/interpreter/things/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,27 @@ impl PropertyValueExt for fastn_resolved::PropertyValue {
loop_object_name_and_kind: &Option<(String, fastn_resolved::Argument, Option<String>)>,
) -> ftd::interpreter::Result<ftd::interpreter::StateWithThing<fastn_resolved::PropertyValue>>
{
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,
)
))
}
}

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2cd9e00

Please sign in to comment.