Skip to content

Commit

Permalink
docs: document the Box::leak trick for static references
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis committed Oct 17, 2023
1 parent cf46827 commit 5f5687e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ async fn main() -> Result<(), std::io::Error> {
// Make an instance of network subgraph at either
// graph_node_query_endpoint/subgraphs/id/network_subgraph_deployment
// or network_subgraph_endpoint
//
// We're leaking the network subgraph here to obtain a reference with
// a static lifetime, which avoids having to pass around and clone `Arc`
// objects everywhere. Since the network subgraph is read-only, this is
// no problem.
let network_subgraph = Box::leak(Box::new(NetworkSubgraph::new(
Some(&config.indexer_infrastructure.graph_node_query_endpoint),
config
Expand Down

0 comments on commit 5f5687e

Please sign in to comment.