pub struct BucketBase { /* private fields */ }
Expand description
§Bucket 元信息
包含所属 bucket 名以及所属的 endpoint
Implementations§
Source§impl BucketBase
impl BucketBase
Sourcepub fn new(name: BucketName, endpoint: EndPoint) -> Self
pub fn new(name: BucketName, endpoint: EndPoint) -> Self
初始化
Sourcepub fn set_internal(&mut self, is_internal: bool)
pub fn set_internal(&mut self, is_internal: bool)
§调整 API 指向是否为内网
当在 Aliyun ECS 上执行时,设为 true 会更高效,默认是 false
Sourcepub fn from_env() -> Result<Self, InvalidConfig>
pub fn from_env() -> Result<Self, InvalidConfig>
Sourcepub fn get_name(&self) -> &BucketName
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()
);
Sourcepub fn endpoint_ref(&self) -> &EndPoint
pub fn endpoint_ref(&self) -> &EndPoint
获取 EndPoint 引用
Sourcepub fn set_name<N: Into<BucketName>>(&mut self, name: N)
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");
Sourcepub fn set_endpoint<E: Into<EndPoint>>(&mut self, endpoint: E)
pub fn set_endpoint<E: Into<EndPoint>>(&mut self, endpoint: E)
为 Bucket 元信息设置可用区
Sourcepub fn try_set_name<N: TryInto<BucketName>>(
&mut self,
name: N,
) -> Result<(), N::Error>
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");
Sourcepub fn try_set_endpoint<E: TryInto<EndPoint>>(
&mut self,
endpoint: E,
) -> Result<(), E::Error>
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);
Sourcepub fn to_url(&self) -> Url
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
Sourcepub fn get_url_resource(&self, query: &Query) -> (Url, CanonicalizedResource)
pub fn get_url_resource(&self, query: &Query) -> (Url, CanonicalizedResource)
根据查询参数,获取当前 bucket 的接口请求参数( url 和 CanonicalizedResource)
Sourcepub fn get_url_resource_with_path(
&self,
path: &ObjectPathInner<'_>,
) -> (Url, CanonicalizedResource)
pub fn get_url_resource_with_path( &self, path: &ObjectPathInner<'_>, ) -> (Url, CanonicalizedResource)
根据查询参数,获取当前 bucket 的接口请求参数( url 和 CanonicalizedResource)
Trait Implementations§
Source§impl AsMut<BucketName> for BucketBase
impl AsMut<BucketName> for BucketBase
Source§fn as_mut(&mut self) -> &mut BucketName
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
impl AsMut<EndPoint> for BucketBase
Source§impl<T: PointerFamily> AsRef<BucketBase> for Bucket<T>
impl<T: PointerFamily> AsRef<BucketBase> for Bucket<T>
Source§fn as_ref(&self) -> &BucketBase
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>
impl<T: PointerFamily, Item> AsRef<BucketBase> for ObjectList<T, Item>
Source§fn as_ref(&self) -> &BucketBase
fn as_ref(&self) -> &BucketBase
Converts this type into a shared reference of the (usually inferred) input type.
Source§impl AsRef<BucketName> for BucketBase
impl AsRef<BucketName> for BucketBase
Source§fn as_ref(&self) -> &BucketName
fn as_ref(&self) -> &BucketName
Converts this type into a shared reference of the (usually inferred) input type.
Source§impl AsRef<EndPoint> for BucketBase
impl AsRef<EndPoint> for BucketBase
Source§impl Clone for BucketBase
impl Clone for BucketBase
Source§fn clone(&self) -> BucketBase
fn clone(&self) -> BucketBase
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for BucketBase
impl Debug for BucketBase
Source§impl Default for BucketBase
impl Default for BucketBase
Source§fn default() -> BucketBase
fn default() -> BucketBase
Returns the “default value” for a type. Read more
Source§impl<M> From<Client<M>> for BucketBase
impl<M> From<Client<M>> for BucketBase
Source§impl FromStr for BucketBase
impl FromStr for BucketBase
Source§fn from_str(domain: &str) -> Result<Self, InvalidBucketBase>
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
type Err = InvalidBucketBase
The associated error which can be returned from parsing.
Source§impl Hash for BucketBase
impl Hash for BucketBase
Source§impl<T: PointerFamily> PartialEq<BucketBase> for Bucket<T>
impl<T: PointerFamily> PartialEq<BucketBase> for Bucket<T>
Source§impl PartialEq<Url> for BucketBase
impl PartialEq<Url> for BucketBase
Source§fn eq(&self, other: &Url) -> bool
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());
Source§impl PartialEq for BucketBase
impl PartialEq for BucketBase
Source§impl TryFrom<&str> for BucketBase
impl TryFrom<&str> for BucketBase
impl Eq for BucketBase
impl StructuralPartialEq for BucketBase
Auto Trait Implementations§
impl Freeze for BucketBase
impl RefUnwindSafe for BucketBase
impl Send for BucketBase
impl Sync for BucketBase
impl Unpin for BucketBase
impl UnwindSafe for BucketBase
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.