use futures_core::future::BoxFuture;
use std::future::Future;
use std::time::Duration;
use tokio::runtime::Handle;
use ve_tos_rust_sdk::common::init_tracing_log;
use ve_tos_rust_sdk::asynchronous::bucket::BucketAPI;
use ve_tos_rust_sdk::asynchronous::tos;
use ve_tos_rust_sdk::asynchronous::tos::AsyncRuntime;
use ve_tos_rust_sdk::bucket::GetBucketReplicationInput;
use ve_tos_rust_sdk::error::TosError;
#[derive(Debug, Default)]
pub struct TokioRuntime {}
#[async_trait::async_trait]
impl AsyncRuntime for TokioRuntime {
type JoinError = tokio::task::JoinError;
async fn sleep(&self, duration: Duration) {
tokio::time::sleep(duration).await;
fn spawn<'a, F>(&self, future: F) -> BoxFuture<'a, Result<F::Output, Self::JoinError>>
F: Future + Send + 'static,
F::Output: Send + 'static,
Box::pin(Handle::current().spawn(future))
fn block_on<F: Future>(&self, future: F) -> F::Output {
Handle::current().block_on(future)
let _guard = init_tracing_log("info", "temp/logs", "app.log");
let ak = env::var("TOS_ACCESS_KEY").expect("TOS_ACCESS_KEY未设置");
let sk = env::var("TOS_SECRET_KEY").expect("TOS_SECRET_KEY未设置");
let endpoint = "https://tos-cn-beijing.volces.com";
let region = "cn-beijing";
let client = tos::builder::<TokioRuntime>()
.connection_timeout(3000)
.build().expect("客户端构建失败");
let bucket_name = "your-bucket-name";
let rule_id = "rule-123";
let mut input = GetBucketReplicationInput::default();
input.set_bucket(bucket_name);
input.set_rule_id(rule_id);
let result = client.get_bucket_replication(&input).await;
println!("请求ID: {}", output.request_id());
println!("复制角色: {}", output.role());
if let Some(rule) = output.rules().iter().find(|r| r.id() == rule_id) {
println!("\n找到规则 ID={}:", rule_id);
println!(" 状态: {:?}", rule.status());
println!(" 前缀集合: {:?}", rule.prefix_set());
println!(" 目标存储桶: {}", rule.destination().bucket());
println!(" 历史对象复制状态: {:?}", rule.historical_object_replication());
println!("未找到规则 ID={}", rule_id);
TosError::TosClientError { message, .. } => {
eprintln!("客户端错误: {}", message);
TosError::TosServerError { request_id, ec, .. } => {
eprintln!("服务端错误: 请求ID={}, 错误码={}", request_id, ec);
eprintln!("未知错误: {:?}", err);