DEV Community

Discussion on: How actix-web's application state and Data extractor works internally

Collapse
 
fakeshadow profile image
fakeshadow • Edited

Data is typed based so you can always use new type for uniqueness. Like PgConnection1<PgConnection> and PgConnection2<PgConnection>. After that you can impl Deref and DerefMut for auto dereference to the inner type

Collapse
 
joshchoo profile image
Josh • Edited

Indeed! If we add the same types via .app_data(...), the most recently inserted one overrides the rest. Here's a relevant chapter from The Rust Programming Language book that @fakeshadow is talking about:

doc.rust-lang.org/stable/book/ch15...