pub struct Storage { /* private fields */ }Expand description
Implements a client for the Cloud Storage API.
§Example
let client = Storage::builder().build().await?;
// use `client` to make requests to Cloud Storage.§Configuration
To configure Storage use the with_* methods in the type returned
by builder(). The default configuration should
work for most applications. Common configuration changes include
- with_endpoint(): by default this client uses the global default endpoint
(
https://storage.googleapis.com). Applications using regional endpoints or running in restricted networks (e.g. a network configured with Private Google Access with VPC Service Controls) may want to override this default. - with_credentials(): by default this client uses Application Default Credentials. Applications using custom authentication may need to override this default.
§Pooling and Cloning
Storage holds a connection pool internally, it is advised to
create one and then reuse it. You do not need to wrap Storage in
an Rc or Arc to reuse it, because it already uses an Arc
internally.
§Service Description
The Cloud Storage API allows applications to read and write data through the abstractions of buckets and objects. For a description of these abstractions please see https://cloud.google.com/storage/docs.
Resources are named as follows:
-
Projects are referred to as they are defined by the Resource Manager API, using strings like
projects/123456orprojects/my-string-id. -
Buckets are named using string names of the form:
projects/{project}/buckets/{bucket}For globally unique buckets,_may be substituted for the project. -
Objects are uniquely identified by their name along with the name of the bucket they belong to, as separate strings in this API. For example:
bucket = "projects/_/buckets/my-bucket" object = "my-object/with/a/folder-like/name"Note that object names can contain
/characters, which are treated as any other character (no special directory semantics).
Implementations§
Source§impl Storage
impl Storage
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Sourcepub fn upload_object<B, O, T, P>(
&self,
bucket: B,
object: O,
payload: T,
) -> UploadObject<P, Crc32c>
pub fn upload_object<B, O, T, P>( &self, bucket: B, object: O, payload: T, ) -> UploadObject<P, Crc32c>
Upload an object using a local buffer.
If the data source does not implement Seek the client library must buffer uploaded data until this data is persisted in the service. This requires more memory in the client, and when the buffer grows too large, may require stalling the upload until the service can persist the data.
Use this function for data sources representing computations where it is expensive or impossible to restart said computation. This function is also useful when it is hard or impossible to predict the number of bytes emitted by a stream, even if restarting the stream is not too expensive.
§Example
let response = client
.upload_object("projects/_/buckets/my-bucket", "my-object", "hello world")
.send_buffered()
.await?;
println!("response details={response:?}");§Example
let response = client
.upload_object("projects/_/buckets/my-bucket", "my-object", "hello world")
.send_unbuffered()
.await?;
println!("response details={response:?}");§Parameters
bucket- the bucket name containing the object. Inprojects/_/buckets/{bucket_id}format.object- the object name.payload- the object data.
Sourcepub fn read_object<B, O>(&self, bucket: B, object: O) -> ReadObject
pub fn read_object<B, O>(&self, bucket: B, object: O) -> ReadObject
Downloads the contents of an object.
§Example
let mut resp = client
.read_object("projects/_/buckets/my-bucket", "my-object")
.send()
.await?;
let mut contents = Vec::new();
while let Some(chunk) = resp.next().await.transpose()? {
contents.extend_from_slice(&chunk);
}
println!("object contents={:?}", bytes::Bytes::from_owner(contents));§Parameters
bucket- the bucket name containing the object. Inprojects/_/buckets/{bucket_id}format.object- the object name.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Storage
impl !RefUnwindSafe for Storage
impl Send for Storage
impl Sync for Storage
impl Unpin for Storage
impl !UnwindSafe for Storage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request