From 799cbff462b2bec0afbe72a11907ca73dd8971f3 Mon Sep 17 00:00:00 2001 From: tu6ge Date: Fri, 19 May 2023 16:12:31 +0800 Subject: [PATCH] Revert "feat(file)!: GetStd GetStdWithPath remove method" This reverts commit 087c3c63b276a562b4bd8502fe085fd918b6924e. --- src/file.rs | 130 +++++++++++++---------------------------------- src/file/test.rs | 6 +-- 2 files changed, 39 insertions(+), 97 deletions(-) diff --git a/src/file.rs b/src/file.rs index bb52e85..497a3e7 100644 --- a/src/file.rs +++ b/src/file.rs @@ -87,8 +87,9 @@ use crate::{ bucket::Bucket, builder::{ArcPointer, BuilderError, RequestBuilder}, decode::RefineObject, - object::ObjectList, - types::{object::ObjectPath, CanonicalizedResource, ContentRange}, + object::{Object, ObjectList}, + types::object::{ObjectBase, ObjectPath}, + types::{CanonicalizedResource, ContentRange}, }; #[cfg(feature = "put_file")] use infer::Infer; @@ -177,57 +178,28 @@ where } } -pub use get_std::GetStd; - -mod get_std { - use url::Url; - - use crate::{ - builder::ArcPointer, - object::Object, - types::{object::ObjectBase, CanonicalizedResource}, - }; - - /// 获取请求 OSS 接口需要的信息 - pub trait GetStd: Sealed {} - - impl GetStd for ObjectBase {} - impl GetStd for Object {} - - pub trait Sealed { - /// 获取 `Url` 和 `CanonicalizedResource` - fn get_std(&self) -> Option<(Url, CanonicalizedResource)>; - } +/// 获取请求 OSS 接口需要的信息 +pub trait GetStd { + /// 获取 `Url` 和 `CanonicalizedResource` + fn get_std(&self) -> Option<(Url, CanonicalizedResource)>; +} - impl Sealed for ObjectBase { - #[inline(always)] - fn get_std(&self) -> Option<(Url, CanonicalizedResource)> { - Some(self.get_url_resource([])) - } +impl GetStd for ObjectBase { + fn get_std(&self) -> Option<(Url, CanonicalizedResource)> { + Some(self.get_url_resource([])) } +} - impl Sealed for Object { - #[inline(always)] - fn get_std(&self) -> Option<(Url, CanonicalizedResource)> { - Some(self.base.get_url_resource([])) - } +impl GetStd for Object { + fn get_std(&self) -> Option<(Url, CanonicalizedResource)> { + Some(self.base.get_url_resource([])) } } -pub use get_std_with_path::GetStdWithPath; - -mod get_std_with_path { - use url::Url; - - use crate::types::CanonicalizedResource; - - /// 根据给定路径,获取请求 OSS 接口需要的信息 - pub trait GetStdWithPath: Sealed {} - - pub trait Sealed { - /// 根据 path 获取 `Url` 和 `CanonicalizedResource` - fn get_std_with_path(&self, _path: Path) -> Option<(Url, CanonicalizedResource)>; - } +/// 根据给定路径,获取请求 OSS 接口需要的信息 +pub trait GetStdWithPath { + /// 根据 path 获取 `Url` 和 `CanonicalizedResource` + fn get_std_with_path(&self, _path: Path) -> Option<(Url, CanonicalizedResource)>; } #[doc(hidden)] @@ -240,10 +212,7 @@ pub mod std_path_impl { #[cfg(feature = "blocking")] use crate::client::ClientRc; - use super::{ - get_std_with_path::{GetStdWithPath, Sealed}, - GetStd, - }; + use super::{GetStd, GetStdWithPath}; use crate::{ bucket::Bucket, builder::ArcPointer, @@ -257,35 +226,13 @@ pub mod std_path_impl { use oss_derive::oss_gen_rc; use reqwest::Url; - #[oss_gen_rc] - impl GetStdWithPath for ClientArc {} - #[oss_gen_rc] - impl GetStdWithPath<&str> for ClientArc {} - #[oss_gen_rc] - impl GetStdWithPath for ClientArc {} - #[oss_gen_rc] - impl> GetStdWithPath for ClientArc {} - impl> GetStdWithPath for B {} - impl> GetStdWithPath<&str> for B {} - impl> GetStdWithPath for B {} - impl> GetStdWithPath<&ObjectPath> for B {} - #[oss_gen_rc] - impl GetStdWithPath> for Bucket {} - #[oss_gen_rc] - impl GetStdWithPath<&ObjectBase> for Bucket {} - impl + Send + Sync, E: Error + Send + Sync, U: GetStd> GetStdWithPath - for ObjectList - { - } - /// # 用于在 Client 上对文件进行操作 /// /// 文件路径可以是 `String` 类型 /// /// [`ObjectPath`]: crate::ObjectPath #[oss_gen_rc] - impl Sealed for ClientArc { - #[inline(always)] + impl GetStdWithPath for ClientArc { fn get_std_with_path(&self, path: String) -> Option<(Url, CanonicalizedResource)> { let object_path = path.try_into().ok()?; Some(get_url_resource(self, self, &object_path)) @@ -298,8 +245,7 @@ pub mod std_path_impl { /// /// [`ObjectPath`]: crate::ObjectPath #[oss_gen_rc] - impl Sealed<&str> for ClientArc { - #[inline(always)] + impl GetStdWithPath<&str> for ClientArc { fn get_std_with_path(&self, path: &str) -> Option<(Url, CanonicalizedResource)> { let object_path = path.try_into().ok()?; Some(get_url_resource(self, self, &object_path)) @@ -312,8 +258,7 @@ pub mod std_path_impl { /// /// [`ObjectPath`]: crate::ObjectPath #[oss_gen_rc] - impl Sealed for ClientArc { - #[inline(always)] + impl GetStdWithPath for ClientArc { fn get_std_with_path(&self, path: ObjectPath) -> Option<(Url, CanonicalizedResource)> { Some(get_url_resource(self, self, &path)) } @@ -325,8 +270,7 @@ pub mod std_path_impl { /// /// [`&ObjectPath`]: crate::ObjectPath #[oss_gen_rc] - impl> Sealed for ClientArc { - #[inline(always)] + impl> GetStdWithPath for ClientArc { fn get_std_with_path(&self, path: Path) -> Option<(Url, CanonicalizedResource)> { Some(get_url_resource(self, self, path.as_ref())) } @@ -335,8 +279,7 @@ pub mod std_path_impl { /// # 用于在 Bucket 上对文件进行操作 /// /// 文件路径可以是 `String` 类型 - impl> Sealed for B { - #[inline(always)] + impl> GetStdWithPath for B { fn get_std_with_path(&self, path: String) -> Option<(Url, CanonicalizedResource)> { let path = path.try_into().ok()?; Some(self.as_ref().get_url_resource_with_path(&path)) @@ -346,8 +289,7 @@ pub mod std_path_impl { /// # 用于在 Bucket 上对文件进行操作 /// /// 文件路径可以是 `&str` 类型 - impl> Sealed<&str> for B { - #[inline(always)] + impl> GetStdWithPath<&str> for B { fn get_std_with_path(&self, path: &str) -> Option<(Url, CanonicalizedResource)> { let path = path.try_into().ok()?; Some(self.as_ref().get_url_resource_with_path(&path)) @@ -359,8 +301,8 @@ pub mod std_path_impl { /// 文件路径可以是 [`ObjectPath`] 类型 /// /// [`ObjectPath`]: crate::ObjectPath - impl> Sealed for B { - #[inline(always)] + impl> GetStdWithPath for B { + #[inline] fn get_std_with_path(&self, path: ObjectPath) -> Option<(Url, CanonicalizedResource)> { Some(self.as_ref().get_url_resource_with_path(&path)) } @@ -371,8 +313,8 @@ pub mod std_path_impl { /// 文件路径可以是 [`&ObjectPath`] 类型 /// /// [`&ObjectPath`]: crate::ObjectPath - impl> Sealed<&ObjectPath> for B { - #[inline(always)] + impl> GetStdWithPath<&ObjectPath> for B { + #[inline] fn get_std_with_path(&self, path: &ObjectPath) -> Option<(Url, CanonicalizedResource)> { Some(self.as_ref().get_url_resource_with_path(path)) } @@ -384,8 +326,8 @@ pub mod std_path_impl { /// /// [`ObjectBase`]: crate::types::object::ObjectBase #[oss_gen_rc] - impl Sealed> for Bucket { - #[inline(always)] + impl GetStdWithPath> for Bucket { + #[inline] fn get_std_with_path( &self, base: ObjectBase, @@ -400,8 +342,8 @@ pub mod std_path_impl { /// /// [`&ObjectBase`]: crate::types::object::ObjectBase #[oss_gen_rc] - impl Sealed<&ObjectBase> for Bucket { - #[inline(always)] + impl GetStdWithPath<&ObjectBase> for Bucket { + #[inline] fn get_std_with_path( &self, base: &ObjectBase, @@ -415,10 +357,10 @@ pub mod std_path_impl { /// 文件路径可以是实现 [`GetStd`] 特征的类型 /// /// [`GetStd`]: crate::file::GetStd - impl + Send + Sync, E: Error + Send + Sync, U: GetStd> Sealed + impl + Send + Sync, E: Error + Send + Sync, U: GetStd> GetStdWithPath for ObjectList { - #[inline(always)] + #[inline] fn get_std_with_path(&self, path: U) -> Option<(Url, CanonicalizedResource)> { path.get_std() } diff --git a/src/file/test.rs b/src/file/test.rs index 4f4632a..0efa0a8 100644 --- a/src/file/test.rs +++ b/src/file/test.rs @@ -6,7 +6,7 @@ mod tests_get_std { use reqwest::Url; use std::sync::Arc; - use crate::file::get_std::Sealed; + use crate::file::GetStd; use crate::{ builder::ArcPointer, object::Object, @@ -49,7 +49,7 @@ mod tests_get_std { #[test] fn test_object_ref() { let object = Object::::default(); - let res = Sealed::get_std(&object); + let res = GetStd::get_std(&object); assert!(res.is_some()); let (url, resource) = res.unwrap(); @@ -68,7 +68,7 @@ mod test_get_std_with_path { bucket::Bucket, builder::ArcPointer, client::ClientArc, - file::get_std_with_path::Sealed, + file::GetStdWithPath, object::Object, types::{object::ObjectBase, CanonicalizedResource}, ObjectPath,