Skip to content

Queryable is not object-safe #352

Answered by blackbeam
jobayle asked this question in Q&A
May 15, 2023 · 2 comments · 3 replies
Discussion options

You must be logged in to vote
pub fn dump_table(conn: &mut Conn, schema: &String, table: &String) -> Result<()> {...} // Allowed
pub fn dump_table(conn: &mut dyn Queryable, schema: &String, table: &String) -> Result<()> {...} // the trait `mysql::prelude::Queryable` cannot be made into an object
pub fn dump_table(conn: Box<dyn Queryable>, schema: &String, table: &String) -> Result<()> {...} // the trait `mysql::prelude::Queryable` cannot be made into an object

Never tried dynamic dispatch, actually. Always using generics instead:

fn by_id<T>(conn: &mut T, id: u64) -> crate::Result<Self>
where
    T: Queryable,
{
    \\ ...
}

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@jobayle
Comment options

@blackbeam
Comment options

@jobayle
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by jobayle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants