pub struct Storage<S = DefaultStorage>where
S: Storage + 'static,{ /* 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<S> Storage<S>where
S: Storage + 'static,
impl<S> Storage<S>where
S: Storage + 'static,
Sourcepub fn from_stub(stub: S) -> Selfwhere
S: Storage + 'static,
pub fn from_stub(stub: S) -> Selfwhere
S: Storage + 'static,
Creates a new client from the provided stub.
The most common case for calling this function is in tests mocking the client’s behavior.
Sourcepub fn write_object<B, O, T, P>(
&self,
bucket: B,
object: O,
payload: T,
) -> WriteObject<P, S>
pub fn write_object<B, O, T, P>( &self, bucket: B, object: O, payload: T, ) -> WriteObject<P, S>
Write an object with data from any data source.
§Example
let response = client
.write_object("projects/_/buckets/my-bucket", "my-object", "hello world")
.send_buffered()
.await?;
println!("response details={response:?}");§Example
let response = client
.write_object("projects/_/buckets/my-bucket", "my-object", "hello world")
.send_unbuffered()
.await?;
println!("response details={response:?}");You can use many different types as the payload. For example, a string, a bytes::Bytes, a tokio::fs::File, or a custom type that implements the StreamingSource trait.
If your data source also implements Seek, prefer send_unbuffered() to start the write. Otherwise use send_buffered().
§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<S>
pub fn read_object<B, O>(&self, bucket: B, object: O) -> ReadObject<S>
Reads 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<S> Freeze for Storage<S>
impl<S = Storage> !RefUnwindSafe for Storage<S>
impl<S> Send for Storage<S>
impl<S> Sync for Storage<S>
impl<S> Unpin for Storage<S>
impl<S = Storage> !UnwindSafe for Storage<S>
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