Client

Struct Client 

Source
pub struct Client { /* private fields */ }

Implementations§

Source§

impl Client

Source

pub fn new( secrect_id: impl Into<String>, secrect_key: impl Into<String>, bucket: impl Into<String>, region: impl Into<String>, ) -> Self

Source

pub fn get_host(&self) -> String

Source

pub fn get_secrect_key(&self) -> &str

Source

pub fn get_secrect_id(&self) -> &str

Source

pub fn gen_common_headers(&self) -> HashMap<String, String>

Source

pub fn get_full_url_from_path(&self, path: &str) -> String

Source

pub fn get_path_from_object_key(&self, key: &str) -> String

Source

pub fn get_host_for_bucket_query(&self) -> String

Source

pub fn get_headers_with_auth( &self, method: &str, url_path: &str, acl_header: Option<&AclHeader>, origin_headers: Option<HashMap<String, String>>, query: Option<&HashMap<String, String>>, ) -> HashMap<String, String>

Source

pub fn make_response(&self, resp: Result<Response, Response>) -> Response

Source

pub fn get_presigned_download_url( &self, object_key: &str, expire: u32, ) -> String

获取预签名下载URL 见官网文档

Trait Implementations§

Source§

impl Bucket for Client

Source§

fn put_bucket<'life0, 'life1, 'async_trait>( &'life0 self, acl_header: Option<&'life1 AclHeader>, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

创建一个存储桶 见官网文档

§Examples
use rust_qcos::client::Client;
use rust_qcos::bucket::Bucket;
use rust_qcos::acl::{AclHeader, BucketAcl};
async {
let mut acl_header = AclHeader::new();
acl_header.insert_bucket_x_cos_acl(BucketAcl::PublicRead);
let client = Client::new("foo", "bar", "qcloudtest-1256650966", "ap-guangzhou");
let res = client.put_bucket(Some(&acl_header)).await;
assert!(res.error_message.contains("403"));
};
Source§

fn delete_bucket<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

删除指定的存储桶。该 API 的请求者需要对存储桶有写入权限。 见官网文档

§Examples
use rust_qcos::client::Client;
use rust_qcos::bucket::Bucket;
async {
let client = Client::new("foo", "bar", "qcloudtest-1256650966", "ap-guangzhou");
let res = client.delete_bucket().await;
assert!(res.error_message.contains("403"));
};
Source§

fn list_objects<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, prefix: &'life1 str, delimiter: &'life2 str, encoding_type: &'life3 str, marker: &'life4 str, max_keys: i32, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

列出该存储桶内的部分或者全部对象。该 API 的请求者需要对存储桶有读取权限。 见官网文档

§Examples
use rust_qcos::client::Client;
use rust_qcos::bucket::Bucket;
async {
let client = Client::new("foo", "bar", "qcloudtest-1256650966", "ap-guangzhou");
let res = client.list_objects("prefix", "", "", "/", 100).await;
assert!(res.error_message.contains("403"));
};
Source§

fn check_bucket<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

确认该存储桶是否存在,是否有权限访问 官网文档 存储桶存在且有读取权限,返回 SUCCESS 无存储桶读取权限,返回 ErrNo::STATUS, error_message包含403。 存储桶不存在,返回 ErrNo::STATUS, error_message包含404。

§Examples
use rust_qcos::client::Client;
use rust_qcos::bucket::Bucket;
async {
let client = Client::new("foo", "bar", "qcloudtest-1256650966", "ap-guangzhou");
let res = client.check_bucket().await;
assert!(res.error_message.contains("403"));
};
Source§

fn put_bucket_acl<'life0, 'life1, 'async_trait>( &'life0 self, acl_header: &'life1 AclHeader, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

写入存储桶的访问控制列表 官网文档

§Examples
use rust_qcos::client::Client;
use rust_qcos::bucket::Bucket;
use rust_qcos::acl::{AclHeader, BucketAcl};
async {
let mut acl_header = AclHeader::new();
acl_header.insert_bucket_x_cos_acl(BucketAcl::PublicRead);
let client = Client::new("foo", "bar", "qcloudtest-1256650966", "ap-guangzhou");
let res = client.put_bucket(Some(&acl_header)).await;
assert!(res.error_message.contains("403"));
};
Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Objects for Client

Source§

fn put_object<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, content_type: Mime, key: &'life1 str, data: Vec<u8>, acl_header: Option<&'life2 AclHeader>, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

上传本地小文件 见官网文档

§Examples
use rust_qcos::client::Client;
use rust_qcos::objects::Objects;
use mime;
use rust_qcos::acl::{AclHeader, ObjectAcl};
async {
let mut acl_header = AclHeader::new();
acl_header.insert_object_x_cos_acl(ObjectAcl::AuthenticatedRead);
let client = Client::new("foo", "bar", "qcloudtest-1256650966", "ap-guangzhou");
let data = std::fs::read("Cargo.toml").unwrap();
let res = client.put_object(mime::TEXT_PLAIN_UTF_8, "Cargo.toml", data, None).await;
assert!(res.error_message.contains("403"));
};
Source§

fn put_big_object<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, file_path: &'life1 str, key: &'life2 str, content_type: Mime, storage_class: &'life3 str, acl_header: Option<&'life4 AclHeader>, part_size: u64, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

上传本地大文件 见官网文档

§Examples
use rust_qcos::client::Client;
use rust_qcos::objects::Objects;
use mime;
use rust_qcos::acl::{AclHeader, ObjectAcl};
async {
let mut acl_header = AclHeader::new();
acl_header.insert_object_x_cos_acl(ObjectAcl::AuthenticatedRead);
let client = Client::new("foo", "bar", "qcloudtest-1256650966", "ap-guangzhou");
// 分块传输
let res = client.put_big_object("Cargo.toml","Cargo.toml", mime::TEXT_PLAIN_UTF_8, "ARCHIVE", Some(&acl_header), 1024 * 1024 * 100).await;
assert!(res.error_message.contains("403"));
};
Source§

fn delete_object<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

删除文件 见官网文档

§Examples
use rust_qcos::client::Client;
use rust_qcos::objects::Objects;
async {
let client = Client::new("foo", "bar", "qcloudtest-1256650966", "ap-guangzhou");
let res = client.delete_object("Cargo.toml").await;
assert!(res.error_message.contains("403"))
};
Source§

fn get_object_binary<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

下载文件二进制流 见官网文档

§Examples
use rust_qcos::client::Client;
use rust_qcos::objects::Objects;
async {
let client = Client::new("foo", "bar", "qcloudtest-1256650966", "ap-guangzhou");
let res = client.get_object_binary("Cargo.toml").await;
assert!(res.error_message.contains("403"));
};
Source§

fn get_object<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, file_name: &'life2 str, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

下载文件到本地 见官网文档

§Examples
use rust_qcos::client::Client;
use rust_qcos::objects::Objects;
async {
let client = Client::new("foo", "bar", "qcloudtest-1256650966", "ap-guangzhou");
let res = client.get_object("Cargo.toml", "Cargo.toml").await;
assert!(res.error_message.contains("403"));
};
Source§

fn put_object_get_upload_id<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, key: &'life1 str, content_type: &'life2 Mime, storage_class: &'life3 str, acl_header: Option<&'life4 AclHeader>, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

请求实现初始化分块上传,成功执行此请求后将返回 UploadId,用于后续的 Upload Part 请求 官网文档

Source§

fn put_object_part<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, key: &'life1 str, upload_id: &'life2 str, part_number: u64, body: Vec<u8>, content_type: &'life3 Mime, acl_header: Option<&'life4 AclHeader>, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

分块上传文件 官网文档

Source§

fn put_object_complete_part<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, key: &'life1 str, etag_map: &'life2 HashMap<u64, String>, upload_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

完成分块上传 官网文档

Source§

fn abort_object_part<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, upload_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

终止分块上传,清理文件碎片 官网文档

Source§

fn head_object<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

判断文件是否存在
Source§

impl Service for Client

Source§

fn get_bucket_list<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

查询请求者名下的所有存储桶列表或特定地域下的存储桶列表 见文档

§Examples
use rust_qcos::client::Client;
use rust_qcos::service::Service;
async {
let client = Client::new("foo", "bar", "qcloudtest-1256650966", "ap-guangzhou");
let resp = client.get_bucket_list().await;
assert!(resp.error_message.contains("403"));
};

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,