Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upCustom types questions #1288
Comments
weiznich
added
the
question
label
Nov 7, 2017
This comment has been minimized.
It is generally possible to reuse type conversions that diesel already implements. For example if you want to map the values of an enum to integer values you could implement enum MyEnum {
A = 1,
B = 2,
}
impl<DB: Backend> ToSql<SmallInt, DB> for MyEnum {
fn to_sql<W: Write>(&self, out: &mut ToSqlOutput<W, DB>) -> Result<IsNull, Box<Error + Send + Sync>> {
match *self {
MyEnum::A => <i16 as ToSql<SmallInt, DB>>::to_sql(&1, out),
MyEnum::B => <i16 as ToSql<SmallInt, DB>>::to_sql(&2, out),
}
}
}( Unfortunately it is not possible to implement this straightforward for
I think this is currently not possible, but I may be wrong about it. |
abhikp commentedNov 1, 2017
•
edited
Hi! I'm starting to write some custom types and had a few questions:
Thanks for your help!