Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions src/stdlib/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,41 @@ pub fn native_contains(args: Vec<Value>) -> Result<Value, RuntimeError> {
));
}

let list = expect_list(&args[0])?;
let item = &args[1];

for value in list.borrow().iter() {
if value == item {
return Ok(Value::Bool(true));
match &args[0] {
Value::List(list) => {
let item = &args[1];
for value in list.borrow().iter() {
if value == item {
return Ok(Value::Bool(true));
}
}
Ok(Value::Bool(false))
}
Value::Text(text) => {
let substring = match &args[1] {
Value::Text(s) => s,
_ => {
return Err(RuntimeError::new(
format!(
"contains on text expects a text argument, got {}",
args[1].type_name()
),
0,
0,
));
}
};
Ok(Value::Bool(text.contains(&**substring)))

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double dereference &**substring is unclear and could be simplified. Consider using substring.as_ref() for better readability.

Suggested change
Ok(Value::Bool(text.contains(&**substring)))
Ok(Value::Bool(text.contains(substring.as_ref())))

Copilot uses AI. Check for mistakes.
}
_ => Err(RuntimeError::new(
format!(
"contains expects a list or text, got {}",
args[0].type_name()
),
0,
0,
)),
}

Ok(Value::Bool(false))
}

pub fn native_indexof(args: Vec<Value>) -> Result<Value, RuntimeError> {
Expand Down
19 changes: 0 additions & 19 deletions src/stdlib/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,6 @@ pub fn native_tolowercase(args: Vec<Value>) -> Result<Value, RuntimeError> {
Ok(Value::Text(Rc::from(lowercase)))
}

pub fn native_contains(args: Vec<Value>) -> Result<Value, RuntimeError> {
if args.len() != 2 {
return Err(RuntimeError::new(
format!("contains expects 2 arguments, got {}", args.len()),
0,
0,
));
}

let text = expect_text(&args[0])?;
let substring = expect_text(&args[1])?;

Ok(Value::Bool(text.contains(&*substring)))
}

pub fn native_substring(args: Vec<Value>) -> Result<Value, RuntimeError> {
if args.len() != 3 {
return Err(RuntimeError::new(
Expand Down Expand Up @@ -320,10 +305,6 @@ pub fn register_text(env: &mut Environment) {
"tolowercase",
Value::NativeFunction("tolowercase", native_tolowercase),
);
let _ = env.define(
"contains",
Value::NativeFunction("contains", native_contains),
);
let _ = env.define(
"substring",
Value::NativeFunction("substring", native_substring),
Expand Down