Structs and methods
Focus: one Task struct and one method that returns an updated copy.
task_methods.slx
struct Task {
id: u64,
title: string,
done: bool
}
fn (task Task) mark_done() -> Task {
return Task {
id: task.id,
title: task.title,
done: true
}
}
entry complete_task(id: u64, title: string) -> Task {
let task: Task = Task {
id,
title,
done: false
}
return task.mark_done()
}How it works
Taskis the contract’s typed return value.fn (task Task) mark_done() -> Taskdeclares a method withtaskas the receiver.complete_task(id, title)creates a new task withdone: false.task.mark_done()returns a newTaskwith the same id and title anddone: true.
Last updated on