#![allow(unused_mut)]
#![allow(unused_imports)]
type BoxFut<'a, T> = ::futures::future::BoxFuture<'a, T>;
type BoxStr<'a, T> = ::futures::stream::BoxStream<'a, T>;
use super::super::stream_paginated;
use super::client::*;
use crate::Result;
use futures::{StreamExt, TryStreamExt};
use std::future::IntoFuture;
use unitycatalog_common::models::volumes::v1::*;
pub struct ListVolumesBuilder {
client: VolumeServiceClient,
request: ListVolumesRequest,
}
impl ListVolumesBuilder {
pub(crate) fn new(
client: VolumeServiceClient,
catalog_name: impl Into<String>,
schema_name: impl Into<String>,
) -> Self {
let request = ListVolumesRequest {
catalog_name: catalog_name.into(),
schema_name: schema_name.into(),
..Default::default()
};
Self { client, request }
}
pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
self.request.max_results = max_results.into();
self
}
pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
self.request.page_token = page_token.into();
self
}
pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
self.request.include_browse = include_browse.into();
self
}
pub fn into_stream(self) -> BoxStr<'static, Result<Volume>> {
let remaining = self.request.max_results;
let stream = stream_paginated(
(self, remaining),
move |(mut builder, mut remaining), page_token| async move {
builder.request.page_token = page_token;
let res = builder.client.list_volumes(&builder.request).await?;
if let Some(ref mut rem) = remaining {
*rem -= res.volumes.len() as i32;
}
let next_page_token = if remaining.is_some_and(|r| r <= 0) {
None
} else {
res.next_page_token.clone()
};
Ok((res, (builder, remaining), next_page_token))
},
)
.map_ok(|resp| futures::stream::iter(resp.volumes.into_iter().map(Ok)))
.try_flatten();
stream.boxed()
}
}
impl IntoFuture for ListVolumesBuilder {
type Output = Result<ListVolumesResponse>;
type IntoFuture = BoxFut<'static, Self::Output>;
fn into_future(self) -> Self::IntoFuture {
let client = self.client;
let request = self.request;
Box::pin(async move { client.list_volumes(&request).await })
}
}
pub struct CreateVolumeBuilder {
client: VolumeServiceClient,
request: CreateVolumeRequest,
}
impl CreateVolumeBuilder {
pub(crate) fn new(
client: VolumeServiceClient,
catalog_name: impl Into<String>,
schema_name: impl Into<String>,
name: impl Into<String>,
volume_type: VolumeType,
) -> Self {
let request = CreateVolumeRequest {
catalog_name: catalog_name.into(),
schema_name: schema_name.into(),
name: name.into(),
volume_type: buffa::EnumValue::Known(volume_type),
..Default::default()
};
Self { client, request }
}
pub fn with_storage_location(mut self, storage_location: impl Into<Option<String>>) -> Self {
self.request.storage_location = storage_location.into();
self
}
pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
self.request.comment = comment.into();
self
}
}
impl IntoFuture for CreateVolumeBuilder {
type Output = Result<Volume>;
type IntoFuture = BoxFut<'static, Self::Output>;
fn into_future(self) -> Self::IntoFuture {
let client = self.client;
let request = self.request;
Box::pin(async move { client.create_volume(&request).await })
}
}
pub struct GetVolumeBuilder {
client: VolumeServiceClient,
request: GetVolumeRequest,
}
impl GetVolumeBuilder {
pub(crate) fn new(client: VolumeServiceClient, name: impl Into<String>) -> Self {
let request = GetVolumeRequest {
name: name.into(),
..Default::default()
};
Self { client, request }
}
pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
self.request.include_browse = include_browse.into();
self
}
}
impl IntoFuture for GetVolumeBuilder {
type Output = Result<Volume>;
type IntoFuture = BoxFut<'static, Self::Output>;
fn into_future(self) -> Self::IntoFuture {
let client = self.client;
let request = self.request;
Box::pin(async move { client.get_volume(&request).await })
}
}
pub struct UpdateVolumeBuilder {
client: VolumeServiceClient,
request: UpdateVolumeRequest,
}
impl UpdateVolumeBuilder {
pub(crate) fn new(client: VolumeServiceClient, name: impl Into<String>) -> Self {
let request = UpdateVolumeRequest {
name: name.into(),
..Default::default()
};
Self { client, request }
}
pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
self.request.new_name = new_name.into();
self
}
pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
self.request.comment = comment.into();
self
}
pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
self.request.owner = owner.into();
self
}
}
impl IntoFuture for UpdateVolumeBuilder {
type Output = Result<Volume>;
type IntoFuture = BoxFut<'static, Self::Output>;
fn into_future(self) -> Self::IntoFuture {
let client = self.client;
let request = self.request;
Box::pin(async move { client.update_volume(&request).await })
}
}
pub struct DeleteVolumeBuilder {
client: VolumeServiceClient,
request: DeleteVolumeRequest,
}
impl DeleteVolumeBuilder {
pub(crate) fn new(client: VolumeServiceClient, name: impl Into<String>) -> Self {
let request = DeleteVolumeRequest {
name: name.into(),
..Default::default()
};
Self { client, request }
}
}
impl IntoFuture for DeleteVolumeBuilder {
type Output = Result<()>;
type IntoFuture = BoxFut<'static, Self::Output>;
fn into_future(self) -> Self::IntoFuture {
let client = self.client;
let request = self.request;
Box::pin(async move { client.delete_volume(&request).await })
}
}