Struct BucketBase

Source
pub struct BucketBase { /* private fields */ }
Expand description

§Bucket 元信息

包含所属 bucket 名以及所属的 endpoint

Implementations§

Source§

impl BucketBase

Source

pub fn new(name: BucketName, endpoint: EndPoint) -> Self

初始化

Source

pub fn set_internal(&mut self, is_internal: bool)

§调整 API 指向是否为内网

当在 Aliyun ECS 上执行时,设为 true 会更高效,默认是 false

Source

pub fn from_env() -> Result<Self, InvalidConfig>

§通过环境变量初始化
§举例
use std::env::set_var;
set_var("ALIYUN_ENDPOINT", "qingdao");
set_var("ALIYUN_BUCKET", "foo1");
assert!(BucketBase::from_env().is_ok());

如果在 Aliyun ECS 上,可将环境变量 ALIYUN_OSS_INTERNAL 设置为 true / 1 / yes / Y ,即可使用 internal 网络请求 OSS 接口

Source

pub fn name(&self) -> &str

返回 bucket 名称的引用

Source

pub fn get_name(&self) -> &BucketName

返回 BucketName 引用

use std::env::set_var;
set_var("ALIYUN_ENDPOINT", "qingdao");
set_var("ALIYUN_BUCKET", "foo1");
assert_eq!(
    *BucketBase::from_env().unwrap().get_name(),
    BucketName::new("foo1").unwrap()
);
Source

pub fn endpoint(self) -> EndPoint

获取 Bucket 元信息中的可用区

Source

pub fn endpoint_ref(&self) -> &EndPoint

获取 EndPoint 引用

Source

pub fn set_name<N: Into<BucketName>>(&mut self, name: N)

设置 bucket name

use aliyun_oss_client::types::BucketName;
let mut bucket = BucketBase::default();
bucket.set_name("abc".parse::<BucketName>().unwrap());
assert_eq!(bucket.name(), "abc");
Source

pub fn set_endpoint<E: Into<EndPoint>>(&mut self, endpoint: E)

为 Bucket 元信息设置可用区

Source

pub fn try_set_name<N: TryInto<BucketName>>( &mut self, name: N, ) -> Result<(), N::Error>

设置 bucket name

let mut bucket = BucketBase::default();
assert!(bucket.try_set_name("abc").is_ok());
assert_eq!(bucket.name(), "abc");
Source

pub fn try_set_endpoint<E: TryInto<EndPoint>>( &mut self, endpoint: E, ) -> Result<(), E::Error>

设置 endpoint

let mut bucket = BucketBase::default();
assert!(bucket.try_set_endpoint("hangzhou").is_ok());
assert_eq!(bucket.endpoint(), EndPoint::HANGZHOU);
Source

pub fn to_url(&self) -> Url

获取url 举例

use aliyun_oss_client::types::BucketName;
let mut bucket = BucketBase::default();
bucket.set_name("abc".parse::<BucketName>().unwrap());
bucket.try_set_endpoint("shanghai").unwrap();
let url = bucket.to_url();
assert_eq!(url.as_str(), "https://abc.oss-cn-shanghai.aliyuncs.com/");

因为 BucketName,EndPoint 声明时已做限制,所以 BucketBase 可以安全的转换成 url

Source

pub fn get_url_resource(&self, query: &Query) -> (Url, CanonicalizedResource)

根据查询参数,获取当前 bucket 的接口请求参数( url 和 CanonicalizedResource)

Source

pub fn get_url_resource_with_path( &self, path: &ObjectPathInner<'_>, ) -> (Url, CanonicalizedResource)

根据查询参数,获取当前 bucket 的接口请求参数( url 和 CanonicalizedResource)

Trait Implementations§

Source§

impl AsMut<BucketName> for BucketBase

Source§

fn as_mut(&mut self) -> &mut BucketName

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<EndPoint> for BucketBase

Source§

fn as_mut(&mut self) -> &mut EndPoint

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T: PointerFamily> AsRef<BucketBase> for Bucket<T>

Source§

fn as_ref(&self) -> &BucketBase

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: PointerFamily, Item> AsRef<BucketBase> for ObjectList<T, Item>

Source§

fn as_ref(&self) -> &BucketBase

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<BucketName> for BucketBase

Source§

fn as_ref(&self) -> &BucketName

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<EndPoint> for BucketBase

Source§

fn as_ref(&self) -> &EndPoint

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for BucketBase

Source§

fn clone(&self) -> BucketBase

Returns a copy 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 Debug for BucketBase

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BucketBase

Source§

fn default() -> BucketBase

Returns the “default value” for a type. Read more
Source§

impl<M> From<Client<M>> for BucketBase

Source§

fn from(_: Client<M>) -> Self

Converts to this type from the input type.
Source§

impl FromStr for BucketBase

Source§

fn from_str(domain: &str) -> Result<Self, InvalidBucketBase>

通过域名获取 举例

let bucket: BucketBase = "abc.oss-cn-shanghai.aliyuncs.com".parse().unwrap();
assert_eq!(bucket.name(), "abc");
assert_eq!(bucket.endpoint(), EndPoint::SHANGHAI);

assert!("abc*#!".parse::<BucketBase>().is_err());
assert!("abc".parse::<BucketBase>().is_err());
Source§

type Err = InvalidBucketBase

The associated error which can be returned from parsing.
Source§

impl Hash for BucketBase

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PointerFamily> PartialEq<BucketBase> for Bucket<T>

Source§

fn eq(&self, other: &BucketBase) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Url> for BucketBase

Source§

fn eq(&self, other: &Url) -> bool

§相等比较
use aliyun_oss_client::types::BucketName;
use reqwest::Url;
let mut bucket = BucketBase::default();
bucket.set_name("abc".parse::<BucketName>().unwrap());
bucket.try_set_endpoint("shanghai").unwrap();
assert!(bucket == Url::parse("https://abc.oss-cn-shanghai.aliyuncs.com/").unwrap());
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for BucketBase

Source§

fn eq(&self, other: &BucketBase) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&str> for BucketBase

Source§

type Error = InvalidBucketBase

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

fn try_from(str: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for BucketBase

Source§

impl StructuralPartialEq for BucketBase

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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,