Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(dead_code)]
- use std::marker::PhantomData;
- struct PgValue<'a>(&'a [u8]);
- struct Pg;
- struct MySql;
- struct Int;
- pub trait FamilyLt<'a> {
- type Out;
- }
- struct IdFamily<T>(PhantomData<T>);
- impl<'a, T> FamilyLt<'a> for IdFamily<T> {
- type Out = T;
- }
- struct RefFamily<T: ?Sized>(PhantomData<T>);
- impl<'a, T: 'a + ?Sized> FamilyLt<'a> for RefFamily<T> {
- type Out = &'a T;
- }
- struct PgValueHelper;
- impl<'a> FamilyLt<'a> for PgValueHelper {
- type Out = PgValue<'a>;
- }
- pub trait Backend: Sized {
- type RawValue: for<'a> FamilyLt<'a>;
- }
- impl Backend for Pg {
- type RawValue = PgValueHelper;
- }
- impl Backend for MySql {
- type RawValue = RefFamily<[u8]>;
- }
- pub trait FromSql<A, DB: Backend>: Sized {
- fn from_sql<'a>(bytes: Option<<DB::RawValue as FamilyLt<'a>>::Out>) -> Result<Self, ()>;
- }
- impl FromSql<Int, Pg> for i32 {
- fn from_sql<'a>(bytes: Option<PgValue<'a>>) -> Result<Self, ()> {
- // just something
- Ok(bytes.unwrap().0[0] as i32)
- }
- }
- pub trait Row<DB: Backend> {
- fn take<'a>(&'a mut self) -> Option<<DB::RawValue as FamilyLt<'a>>::Out>;
- fn next_is_null(&self, count: usize) -> bool;
- fn advance(&mut self, count: usize) {
- for _ in 0..count {
- self.take();
- }
- }
- }
- struct PgResult;
- impl PgResult {
- fn get<'a>(&'a self, _row_idx: usize, _col_idx: usize) -> Option<PgValue<'a>> {
- None
- }
- }
- struct PgRow<'a> {
- db_result: &'a PgResult,
- row_idx: usize,
- col_idx: usize,
- }
- impl<'a> Row<Pg> for PgRow<'a> {
- fn take<'b>(&'b mut self) -> Option<PgValue<'b>> {
- self.db_result.get(self.row_idx, self.col_idx)
- }
- fn next_is_null(&self, _count: usize) -> bool {
- true
- }
- }
- fn main() {
- println!("Hello, world!");
- }
Add Comment
Please, Sign In to add comment