I'm looking at the example at diesel::r2d2 - Rust. It mentions a type DbConnection.
pub fn get_connection_pool() -> Pool<ConnectionManager<DbConnection>> {
let url = database_url_for_env();
let manager = ConnectionManager::<DbConnection>::new(url);
// Refer to the `r2d2` documentation for more methods to use
// when building a connection pool
Pool::builder()
.test_on_check_out(true)
.build(manager)
.expect("Could not build connection pool")
}
How do I find out, what that is and where it comes from? I searched the docs for that string: diesel - Rust, but it doesn't get me anything that brings me a step closer.
I often come across these kind of examples when trying to do things with Rust, and I'm always confused what to do then. I'm sure there's a way to find these things out and I'd love to learn that, so I can better find my way around these things.
The type is in the doctest code, so if the documentation doesn't mention it, and the code is meant to be compiled when testing the crate (which it is, as it should be), you can look into the example source, where you'll see
//! # include!("doctest_setup.rs");
That line is not rendered in the docs, but is compiled with the rest. In the file doctest_setup.rs you'll find:
type DbConnection = PgConnection;
...
type DbConnection = SqliteConnection;
...
type DbConnection = MysqlConnection;
(conditionally compiled according to the passed feature flags.) What they want to say is that any connection type supported by Diesel can appear in place of DbConnection. Perhaps it could be made more clear in the comments or the accompanying text.
Technically, it's a type alias, making it as real as the aliased type, but as it's used only in the examples then yes, you're supposed to use a DB-specific type in your code.