Avatar for the FuelLabs user
FuelLabs
sway
BlogDocsChangelog

Add event support via `#[event]` and `#[indexed]` attributes

#7158
Comparing
tritao:indexed-events
(
6bdb27c
) with
master
(
6553dce
)
CodSpeed Performance Gauge
0%
Untouched
25

Benchmarks

Passed

document_symbol
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::document_symbol
CodSpeed Performance Gauge
+8%
3 ms2.8 ms
semantic_tokens
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::semantic_tokens
CodSpeed Performance Gauge
+1%
2.8 ms2.7 ms
tokens_for_program
sway-lsp/benches/lsp_benchmarks/token_map.rs::benches::benchmarks::tokens_for_program
CodSpeed Performance Gauge
+1%
530.8 µs523.8 µs
code_lens
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::code_lens
CodSpeed Performance Gauge
+1%
4.9 µs4.8 µs
on_enter
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::on_enter
CodSpeed Performance Gauge
0%
124.8 µs124.4 µs
did_change_with_caching
sway-lsp/benches/lsp_benchmarks/compile.rs::benches::benchmarks::did_change_with_caching
CodSpeed Performance Gauge
0%
3.8 ms3.8 ms
idents_at_position
sway-lsp/benches/lsp_benchmarks/token_map.rs::benches::benchmarks::idents_at_position
CodSpeed Performance Gauge
0%
469.6 µs468.6 µs
format
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::format
CodSpeed Performance Gauge
0%
470.5 ms469.6 ms
token_at_position
sway-lsp/benches/lsp_benchmarks/token_map.rs::benches::benchmarks::token_at_position
CodSpeed Performance Gauge
0%
1.5 ms1.5 ms
prepare_rename
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::prepare_rename
CodSpeed Performance Gauge
0%
1.5 ms1.5 ms
completion
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::completion
CodSpeed Performance Gauge
0%
4.9 ms4.9 ms
highlight
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::highlight
CodSpeed Performance Gauge
0%
5.4 ms5.4 ms
code_action
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::code_action
CodSpeed Performance Gauge
0%
5 ms5 ms
parent_decl_at_position
sway-lsp/benches/lsp_benchmarks/token_map.rs::benches::benchmarks::parent_decl_at_position
CodSpeed Performance Gauge
0%
2.8 ms2.8 ms
tokens_at_position
sway-lsp/benches/lsp_benchmarks/token_map.rs::benches::benchmarks::tokens_at_position
CodSpeed Performance Gauge
0%
2.8 ms2.8 ms
find_all_references
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::find_all_references
CodSpeed Performance Gauge
0%
5 ms5 ms
rename
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::rename
CodSpeed Performance Gauge
0%
5 ms5 ms
hover
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::hover
CodSpeed Performance Gauge
0%
1.6 ms1.6 ms
goto_definition
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::goto_definition
CodSpeed Performance Gauge
0%
1.5 ms1.5 ms
compile
sway-lsp/benches/lsp_benchmarks/compile.rs::benches::benchmarks::compile
CodSpeed Performance Gauge
0%
5.5 s5.5 s
open_all_example_workspace_members
sway-lsp/benches/lsp_benchmarks/compile.rs::benches::benchmarks::open_all_example_workspace_members
CodSpeed Performance Gauge
0%
9.8 s9.9 s
tokens_for_file
sway-lsp/benches/lsp_benchmarks/token_map.rs::benches::benchmarks::tokens_for_file
CodSpeed Performance Gauge
0%
1.4 ms1.4 ms
inlay_hints
sway-lsp/benches/lsp_benchmarks/requests.rs::benches::benchmarks::inlay_hints
CodSpeed Performance Gauge
0%
1.9 ms1.9 ms
build_std_lib_docs
forc-plugins/forc-doc/benches/bench_main.rs::benches::benchmarks::build_std_lib_docs
CodSpeed Performance Gauge
0%
309.2 ms310.6 ms
traverse
sway-lsp/benches/lsp_benchmarks/compile.rs::benches::benchmarks::traverse
CodSpeed Performance Gauge
-1%
113 ms113.7 ms

Commits

Click on a commit to change the comparison range
Base
master
6553dce
+0.44%
Add support for events and indexed fields. This adds two new attributes: `#[event]` and `#[indexed]`. The `#[event]` attribute marks a struct or enum as an event that can be emitted by a contract. The `#[indexed]` attribute can be applied to fields within structs that are attributed with `#[event]`. This is particularly useful for event structs, allowing for efficient filtering and searching of emitted events based on the values of these fields. When using this attribute, the indexed fields must be applied sequentially to the initial set of fields in a struct. This attribute can only be applied to fields whose type is an exact size ABI type. The exact size ABI types include: - `bool` - `u8`, `u16`, `u32`, `u64`, `u256` - `numeric` - `b256` - `str[N]` - Tuples containing only exact size types - Structs containing only exact size types - Arrays of exact size types with a literal length - Type aliases to exact size types Additionally it causes the event types to be included in the JSON ABI representation for the contract. ```sway struct MyEventStruct { #[indexed] id: u64, sender: Identity, } enum MyEventEnum { A: (), B: (), } ``` Additionally this updates the JSON ABI to emit an `offset` for indexed fields.
6bdb27c
2 days ago
by tritao
© 2025 CodSpeed Technology
Home Terms Privacy Docs