Archived
2
0
This repository has been archived on 2025-04-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
repo/service/src/search/adapter.rs
T
2025-02-12 09:04:19 +02:00

44 lines
955 B
Rust

use data::search::*;
use data::{Connect, Result};
use std::marker::PhantomData;
pub struct SearchAdapter<D, C, UR>
where
C: Send,
D: Connect<Connection = C> + Sync,
UR: SearchRepository<C> + Sync,
{
driver: D,
_search_repository: PhantomData<UR>,
}
impl<D, C, UR> SearchAdapter<D, C, UR>
where
C: Send,
D: Connect<Connection = C> + Sync,
UR: SearchRepository<C> + Sync,
{
pub const fn new(driver: D) -> Self {
Self {
driver,
_search_repository: PhantomData,
}
}
}
impl<D, C, SR> super::SearchRepository for SearchAdapter<D, C, SR>
where
C: Send, //+ Sync,
D: Connect<Connection = C> + Sync,
SR: SearchRepository<C> + Sync,
{
async fn search(&self, data: Data) -> Result<Vec<Entry>> {
let c = self.driver.open_connection().await?;
let result = SR::search(&c, data).await?;
D::close_connection(c).await?;
Ok(result)
}
}