use async_trait::async_trait;
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::object::ObjectAPI;
use ve_tos_rust_sdk::asynchronous::tos;
use ve_tos_rust_sdk::asynchronous::tos::AsyncRuntime;
use ve_tos_rust_sdk::object::HeadObjectInput;
use ve_tos_rust_sdk::error::TosError;
#[derive(Debug, Default)]
pub struct TokioRuntime {}
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").unwrap_or("".to_string());
let sk = env::var("TOS_SECRET_KEY").unwrap_or("".to_string());
let endpoint = "https://tos-cn-beijing.volces.com";
let region = "cn-beijing";
let client = tos::builder::<TokioRuntime>()
.connection_timeout(3000)
let input = HeadObjectInput::new("example-bucket", "example-object.txt");
let output = client.head_object(&input).await;
println!("etag: {}", output.etag());
if let Some(last_modified) = output.last_modified() {
println!("last_modified: {}", last_modified);
println!("delete_marker: {}", output.delete_marker());
println!("version_id: {}", output.version_id());
println!("object_type: {}", output.object_type());
println!("hash_crc64ecma: {}", output.hash_crc64ecma());
if let Some(storage_class) = output.storage_class() {
println!("storage_class: {:?}", storage_class);
println!("meta entries:");
for (key, value) in output.meta() {
println!(" {}: {}", key, value);
println!("content_length: {}", output.content_length());
println!("cache_control: {}", output.cache_control());
println!("content_disposition: {}", output.content_disposition());
println!("content_encoding: {}", output.content_encoding());
println!("content_language: {}", output.content_language());
println!("content_type: {}", output.content_type());
if let Some(expires) = output.expires() {
println!("expires: {}", expires);
println!("is_directory: {}", output.is_directory());
TosError::TosClientError { message, .. } => {
println!("Client error message: {}", message);
TosError::TosServerError { request_id, ec, code, .. } => {
println!("Server error: request_id: {}, ec: {}, code: {}", request_id, ec, code);
_ => println!("Unexpected error: {:?}", err),