use std::fmt;
use crate::{S3Key, S3Uri};
impl PartialEq<str> for S3Uri {
fn eq(&self, other: &str) -> bool {
self.to_string().eq(other)
}
}
impl PartialEq<&str> for S3Uri {
fn eq(&self, other: &&str) -> bool {
self.to_string().eq(other)
}
}
impl fmt::Display for S3Uri {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self.key {
Some(k) => write!(f, "s3://{}/{}", self.bucket, k),
None => write!(f, "s3://{}/", self.bucket),
}
}
}
impl S3Uri {
pub fn is_prefix(&self) -> bool {
match &self.key {
Some(k) => k.is_prefix(),
None => true,
}
}
pub fn join(&self, part: &str) -> S3Uri {
match &self.key {
Some(k) => S3Uri {
bucket: self.bucket.clone(),
key: Some(k.join(part)),
},
None => S3Uri {
bucket: self.bucket.clone(),
key: Some(S3Key::empty().join(part)),
},
}
}
pub fn leaf(&self) -> Option<&str> {
match &self.key {
Some(k) => k.leaf(),
None => None,
}
}
}