-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use specialization to abstract store steps proof-of-concept
- Loading branch information
Showing
5 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![feature(specialization)] | ||
#![feature(associated_type_defaults)] | ||
#![feature(negative_impls)] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,45 @@ | ||
pub trait UserType {} | ||
pub trait ItemType {} | ||
pub trait ReactionType {} | ||
use async_trait::async_trait; | ||
|
||
use crate::{error::Result, store::Transaction}; | ||
|
||
pub mod store; | ||
|
||
pub trait UserType: Sync {} | ||
pub trait ItemType: Sync {} | ||
pub trait ReactionType: Sync {} | ||
|
||
#[async_trait] | ||
impl<T: ReactionType> store::Storable for T { | ||
default async fn store_reaction( | ||
&self, | ||
txn: &mut impl Transaction, | ||
user: &impl UserType, | ||
item: &impl ItemType, | ||
) -> Result<()> { | ||
println!("store reaction"); | ||
Ok(()) | ||
} | ||
default async fn store_unique_index( | ||
&self, | ||
txn: &mut impl Transaction, | ||
user: &impl UserType, | ||
item: &impl ItemType, | ||
) -> Result<()> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub trait Unique {} | ||
|
||
#[async_trait] | ||
impl<T: ReactionType + Unique> store::Storable for T { | ||
default async fn store_unique_index( | ||
&self, | ||
txn: &mut impl Transaction, | ||
user: &impl UserType, | ||
item: &impl ItemType, | ||
) -> Result<()> { | ||
println!("store unique index"); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use async_trait::async_trait; | ||
|
||
use crate::{error::Result, store::Transaction}; | ||
|
||
use super::{ItemType, UserType}; | ||
|
||
#[async_trait] | ||
pub trait Storable { | ||
async fn store_reaction( | ||
&self, | ||
txn: &mut impl Transaction, | ||
user: &impl UserType, | ||
item: &impl ItemType, | ||
) -> Result<()>; | ||
async fn store_unique_index( | ||
&self, | ||
txn: &mut impl Transaction, | ||
user: &impl UserType, | ||
item: &impl ItemType, | ||
) -> Result<()>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters