Browse Source

Match Go TTL Display: return empty string when unit is Empty

Go checks `t.Unit == Empty` separately and returns "" for TTLs
with nonzero count but Empty unit. Rust only checked is_empty()
(count==0 && unit==0), so count>0 with unit=0 would format as
"5 " instead of "".
rust-volume-server
Chris Lu 4 days ago
parent
commit
8434429f25
  1. 2
      seaweed-volume/src/storage/needle/ttl.rs

2
seaweed-volume/src/storage/needle/ttl.rs

@ -187,7 +187,7 @@ fn unit_to_char(unit: u8) -> char {
impl fmt::Display for TTL { impl fmt::Display for TTL {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.is_empty() {
if self.count == 0 || self.unit == TTL_UNIT_EMPTY {
return write!(f, ""); return write!(f, "");
} }
write!(f, "{}{}", self.count, unit_to_char(self.unit)) write!(f, "{}{}", self.count, unit_to_char(self.unit))

Loading…
Cancel
Save