ali_oss/
bucket.rs

1use std::sync::Mutex;
2#[derive(Debug)]
3pub struct Bucket {
4	pub name: String,
5	pub location: crate::types::BucketLocation,
6	pub comment: String,
7	pub creation_date: Mutex<Option<chrono::DateTime<chrono::Utc>>>,
8}
9
10impl Bucket {
11	pub fn new<T: ToString, U: ToString>(name: T, location: T, comment: U, creation_date: Option<chrono::DateTime<chrono::Utc>>) -> Self {
12		Self {
13			name: name.to_string(),
14			location: crate::types::BucketLocation::new(location),
15			comment: comment.to_string(),
16			creation_date: Mutex::new(creation_date),
17		}
18	}
19	pub fn new_from_xml_node(node: roxmltree::Node) -> anyhow::Result<Self> {
20		let name = node.descendants().find(|n| n.has_tag_name("Name")).and_then(|node| node.text()).unwrap_or("");
21		let location = node.descendants().find(|n| n.has_tag_name("Location")).and_then(|node| node.text()).unwrap_or("");
22		let creation_date = node.descendants().find(|n| n.has_tag_name("CreationDate")).and_then(|node| node.text()).unwrap_or("");
23		let comment = node.descendants().find(|n| n.has_tag_name("Comment")).and_then(|node| node.text()).unwrap_or("");
24		Ok(Self::new(name, location, comment, Some(creation_date.parse()?)))
25	}
26}