Skip to content

Commit b47acca

Browse files
committed
WIP
1 parent daf4a88 commit b47acca

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/rpc/client/tags.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//!
1212
//! [`Client::delete`] can be used to delete a tag.
1313
use anyhow::Result;
14-
use bytes::Bytes;
1514
use futures_lite::{Stream, StreamExt};
1615
use quic_rpc::{client::BoxedConnector, Connector, RpcClient};
1716
use serde::{Deserialize, Serialize};
@@ -44,16 +43,22 @@ where
4443
}
4544

4645
/// Get the value of a single tag
47-
pub async fn get(&self, name: Tag) -> Result<Option<TagInfo>> {
48-
let mut stream = self.rpc.server_streaming(ListRequest::single(name)).await?;
46+
pub async fn get(&self, name: impl AsRef<[u8]>) -> Result<Option<TagInfo>> {
47+
let mut stream = self
48+
.rpc
49+
.server_streaming(ListRequest::single(name.as_ref()))
50+
.await?;
4951
Ok(stream.next().await.transpose()?)
5052
}
5153

5254
/// Lists all tags.
53-
pub async fn list_prefix(&self, prefix: &[u8]) -> Result<impl Stream<Item = Result<TagInfo>>> {
55+
pub async fn list_prefix(
56+
&self,
57+
prefix: impl AsRef<[u8]>,
58+
) -> Result<impl Stream<Item = Result<TagInfo>>> {
5459
let stream = self
5560
.rpc
56-
.server_streaming(ListRequest::prefix(Bytes::copy_from_slice(prefix).into()))
61+
.server_streaming(ListRequest::prefix(prefix.as_ref()))
5762
.await?;
5863
Ok(stream.map(|res| res.map_err(anyhow::Error::from)))
5964
}

src/rpc/proto/tags.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ pub struct ListRequest {
8787

8888
impl ListRequest {
8989
/// List tags with a prefix
90-
pub fn prefix(prefix: Tag) -> Self {
91-
let mut to = prefix.0.to_vec();
90+
pub fn prefix(prefix: &[u8]) -> Self {
91+
let from = prefix.to_vec();
92+
let mut to = from.clone();
93+
let from = Bytes::from(from).into();
9294
let to = if next_prefix(&mut to) {
9395
Some(Bytes::from(to).into())
9496
} else {
@@ -97,21 +99,23 @@ impl ListRequest {
9799
Self {
98100
raw: true,
99101
hash_seq: true,
100-
from: Some(prefix),
102+
from: Some(from),
101103
to,
102104
}
103105
}
104106

105107
/// List a single tag
106-
pub fn single(name: Tag) -> Self {
107-
let mut next = name.0.to_vec();
108+
pub fn single(name: &[u8]) -> Self {
109+
let from = name.to_vec();
110+
let mut next = from.clone();
108111
increment_vec(&mut next);
109-
let next = Bytes::from(next).into();
112+
let from = Bytes::from(from).into();
113+
let to = Bytes::from(next).into();
110114
Self {
111115
raw: true,
112116
hash_seq: true,
113-
from: Some(name),
114-
to: Some(next),
117+
from: Some(from),
118+
to: Some(to),
115119
}
116120
}
117121

0 commit comments

Comments
 (0)