Skip to content

Commit

Permalink
feat: Return StreamInfo from BasinClient::create_stream
Browse files Browse the repository at this point in the history
Signed-off-by: Vaibhav Rabber <[email protected]>
  • Loading branch information
vrongmeal committed Dec 13, 2024
1 parent 5a10e7f commit c3b7585
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ async fn main() {
let basin_client = client.basin_client(basin.clone());

match basin_client.create_stream(create_stream_req).await {
Ok(()) => {
println!("Stream created");
Ok(info) => {
println!("Stream created: {info:?}");
}
Err(ClientError::Service(status)) => {
if status.code() == tonic::Code::AlreadyExists {
Expand Down
5 changes: 4 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,10 @@ impl BasinClient {
}

#[sync_docs]
pub async fn create_stream(&self, req: types::CreateStreamRequest) -> Result<(), ClientError> {
pub async fn create_stream(
&self,
req: types::CreateStreamRequest,
) -> Result<types::StreamInfo, ClientError> {
self.inner
.send_retryable(CreateStreamServiceRequest::new(
self.inner.basin_service_client(),
Expand Down
6 changes: 3 additions & 3 deletions src/service/basin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl CreateStreamServiceRequest {

impl ServiceRequest for CreateStreamServiceRequest {
type ApiRequest = api::CreateStreamRequest;
type Response = ();
type Response = types::StreamInfo;
type ApiResponse = api::CreateStreamResponse;
const IDEMPOTENCY_LEVEL: IdempotencyLevel = IdempotencyLevel::Idempotent;

Expand All @@ -127,9 +127,9 @@ impl ServiceRequest for CreateStreamServiceRequest {

fn parse_response(
&self,
_resp: tonic::Response<Self::ApiResponse>,
resp: tonic::Response<Self::ApiResponse>,
) -> Result<Self::Response, types::ConvertError> {
Ok(())
resp.into_inner().try_into()
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,16 @@ impl From<api::StreamInfo> for StreamInfo {
}
}

impl TryFrom<api::CreateStreamResponse> for StreamInfo {
type Error = ConvertError;

fn try_from(value: api::CreateStreamResponse) -> Result<Self, Self::Error> {
let api::CreateStreamResponse { info } = value;
let info = info.ok_or("missing stream info")?;
Ok(info.into())
}
}

#[sync_docs]
#[derive(Debug, Clone)]
pub struct ListStreamsResponse {
Expand Down

0 comments on commit c3b7585

Please sign in to comment.