rs_split_table/rdb/
row2tab.rs1use core::marker::PhantomData;
4
5use tonic::Status;
6
7pub trait RowToTableName: Sync + Send + 'static {
9 type Row: Send + Sync;
10
11 fn row2table(&self, row: &Self::Row) -> Result<String, Status>;
12}
13
14pub struct RowToTabNameFn<R, F> {
15 orow: PhantomData<R>,
16 row2tab: F,
17}
18
19impl<R, F> RowToTableName for RowToTabNameFn<R, F>
20where
21 F: Fn(&R) -> Result<String, Status> + Send + Sync + 'static,
22 R: Send + Sync + 'static,
23{
24 type Row = R;
25
26 fn row2table(&self, row: &Self::Row) -> Result<String, Status> {
27 (self.row2tab)(row)
28 }
29}
30
31pub fn row2tname_new<R, F>(row2tab: F) -> impl RowToTableName<Row = R>
33where
34 F: Fn(&R) -> Result<String, Status> + Send + Sync + 'static,
35 R: Send + Sync + 'static,
36{
37 RowToTabNameFn {
38 orow: PhantomData,
39 row2tab,
40 }
41}