![]() This value is then used to search app_data's internal hashmap and return the stored PgConnection data that we added to the application state. Given that we use web::Data, Rust will compile copies of the from_request, app_data, get and TypeId::of functions that are specific to the PgConnection type.Īt runtime, when a request hits the /subscriptions route, the PgConnection-specific version of the TypeId::of function will return a concrete TypeId value associated with PgConnection. This process is known as monomorphization. Rust generates different copies of generic functions during compilation for each concrete type needed, such as PgConnection. Enter fullscreen mode Exit fullscreen modeĪha! Given a type, such as PgConnection, Rust allows us to obtain a unique u64 value that identifies it! Hence calling TypeId::of::() gives us a value that we can use a key for the hashmap inside of app_data.īut wait a moment! Isn't PgConnection just a generic type parameter? So, at runtime, how does Rust ensure that calling TypeId::of::() gives us the value associated with PgConnection and not some other type?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |