Skip to content

Commit 378bf5a

Browse files
authored
Convert Client to named fields
1 parent 39f373e commit 378bf5a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

rust/src/client.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,32 @@ use async_trait::async_trait;
44
use postgres::Error;
55
use tokio_postgres as postgres;
66

7-
pub struct Client(u64, postgres::Client);
7+
pub struct Client {
8+
index: u64,
9+
client: postgres::Client,
10+
}
811

912
impl Client {
1013
pub async fn new(client: postgres::Client) -> Result<Client, Error> {
1114
let index = client.query("SELECT * FROM Links;", &[]).await?.len() as u64;
12-
Ok(Self(index, client))
15+
Ok(Self { index, client })
1316
}
1417

1518
pub async fn transaction(&mut self) -> Result<Transaction<'_>, Error> {
16-
let transaction = self.1.transaction().await.unwrap();
17-
Ok(Transaction::new(transaction, self.0))
19+
let transaction = self.client.transaction().await.unwrap();
20+
Ok(Transaction::new(transaction, self.index))
1821
}
1922
}
2023

2124
#[async_trait]
2225
impl Cruds<'_, postgres::Client> for Client {
2326
#[inline]
2427
fn index(&mut self) -> &mut u64 {
25-
&mut self.0
28+
&mut self.index
2629
}
2730

2831
#[inline]
2932
fn executor(&mut self) -> &postgres::Client {
30-
&self.1
33+
&self.client
3134
}
3235
}

0 commit comments

Comments
 (0)