Skip to content

Insert generics by using Insertable<T> as Supertrait #4678

Closed Answered by weiznich
etienneasln asked this question in Q&A
Discussion options

You must be logged in to vote

It is kind of expected that your implementation doesn't work as it misses various trait bounds for the compiler to be able to use the execute method. I generally advice people not to write this kind of generic code and I also do not help people writing such code as they can easily and up with something they cannot maintain. So if you really want to go down that route you are on your own.

That written: The other thing I advice people usually to do is to reconsider if it is even meaningful to refactor that code in such a way.

With your hypothetical implementation you would be able to call

your_type.insert(conn)?;

(Additionally you need to implement your trait for each of your types which is…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@etienneasln
Comment options

Answer selected by etienneasln
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