INNER CODE UNIT · Rust

total_size_as_string

szabodanika/microbin · src/pasta.rs:108

    pub fn total_size_as_string(&self) -> String {
        let mut total_size_bytes = self.content.as_bytes().len();
        if let Some(file) = &self.file {
            total_size_bytes += file.size.as_u64() as usize;
        }
        if let Some(attachments) = &self.attachments {
            for attachment in attachments {
                total_size_bytes += attachment.size.as_u64() as usize;
            }
        }

        if total_size_bytes < 1024 {
            format!("{} B", total_size_bytes)
        } else if total_size_bytes < 1024 * 1024 {
            format!("{} KB", total_size_bytes / 1024)
        } else if total_size_bytes < 1024 * 1024 * 1024 {
            format!("{} MB", total_size_bytes / (1024 * 1024))
        } else {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…