{"id":4460,"date":"2018-08-11T15:56:39","date_gmt":"2018-08-11T20:56:39","guid":{"rendered":"http:\/\/neosmart.net\/blog\/?p=4460"},"modified":"2018-08-11T15:56:39","modified_gmt":"2018-08-11T20:56:39","slug":"prettysize-for-rust","status":"publish","type":"post","link":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/","title":{"rendered":"PrettySize for rust"},"content":{"rendered":"<p><a href=\"https:\/\/neosmart.net\/blog\/wp-content\/uploads\/mannequin-size.png\" rel=\"follow\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4074 size-thumbnail alignright colorbox-4460\" src=\"https:\/\/neosmart.net\/blog\/wp-content\/uploads\/mannequin-size-150x150.png\" alt=\"\" width=\"150\" height=\"150\" srcset=\"https:\/\/neosmart.net\/blog\/wp-content\/uploads\/mannequin-size-150x150.png 150w, https:\/\/neosmart.net\/blog\/wp-content\/uploads\/mannequin-size-600x600.png 600w, https:\/\/neosmart.net\/blog\/wp-content\/uploads\/mannequin-size-1024x1024.png 1024w, https:\/\/neosmart.net\/blog\/wp-content\/uploads\/mannequin-size-300x300.png 300w, https:\/\/neosmart.net\/blog\/wp-content\/uploads\/mannequin-size.png 1200w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a>We&#8217;ve just published a rust port of our PrettySize.NET library, now available <a href=\"https:\/\/crates.io\/crates\/size\" rel=\"nofollow\">via cargo<\/a> and <a href=\"https:\/\/github.com\/neosmart\/prettysize-rs\" rel=\"nofollow\">github<\/a>. Like its .NET predecessor, PrettySize-rs aims to provide a comprehensive API for dealing with file sizes, covering both manipulation and human-readable formatting.<\/p>\n<p><!--more--><\/p>\n<p>Before anything else, here&#8217;s a quick example:<\/p>\n<pre><code class=\"language-rust\">let bytes = 42 * size::MiB;\r\nassert_eq!(bytes, 44040192);\r\n\r\nlet bytes = Size::MiB(42);\r\nprintln!(\"{}\", bytes); \/\/ prints \"42.0 MiB\"\r\n<\/code><\/pre>\n<p>PrettySize 0.1 currently provides the following, which are pretty much essentials when it comes to interacting with file sizes:<\/p>\n<ul>\n<li>Defines for base-two (KiB, MiB, &#8230;) and base-ten (MB, GB, &#8230;) constants in the <code>size<\/code>\u00a0namespace,<\/li>\n<li>A zero-cost, arbitrary-precision type to store file sizes (<code>size::Size<\/code>) annotated with their unit type,<sup id=\"rf1-4460\"><a href=\"#fn1-4460\" title=\"Here, arbitrary precision means that it&rsquo;s actually size::Size&lt;T&gt;&nbsp;where T&nbsp;can be any numeric type.\" rel=\"footnote\">1<\/a><\/sup><\/li>\n<li>A <code>std::fmt::Display<\/code>\u00a0impl for <code>Size<\/code>\u00a0that will emit human-readable values for file sizes (as shown above),<\/li>\n<li>A <code>Size::format(...)<\/code>\u00a0function that provides fine-grained control over the human-readable output, allowing you to format sizes in base-2 or base-10 units, choose between abbreviated and unabbreviated unit names, and lower vs upper case output,<\/li>\n<li>A <code>Size::bytes()<\/code>\u00a0function to retrieve the equivalent byte count for any <code>Size<\/code><\/li>\n<\/ul>\n<p>The currently provided functions should suffice for most cases involving ingestion of file sizes or outputting formatted file sizes for UI or logging purposes; but more work remains to be done.<\/p>\n<p>As with all of our other contributions, PrettySize-rs has been published under the liberal terms of the MIT public license and is available for immediate (re)use or modification at GitHub. Pull requests are both welcomed and appreciated!<\/p>\n<p class=\"save\"><a href=\"https:\/\/github.com\/neosmart\/prettysize-rs\" rel=\"nofollow\">Download PrettySize<\/a><\/p>\n<p align=\"right\">[<a href=\"https:\/\/github.com\/neosmart\/prettysize-rs\/blob\/master\/README.md\" rel=\"nofollow\">readme<\/a>] [<a href=\"https:\/\/docs.rs\/crate\/size\/0.1\" rel=\"nofollow\">docs<\/a>]<\/p>\n<hr class=\"footnotes\"><ol class=\"footnotes\"><li id=\"fn1-4460\"><p>Here, arbitrary precision means that it&#8217;s actually <code>size::Size&lt;T&gt;<\/code>\u00a0where <code>T<\/code>\u00a0can be any numeric type.&nbsp;<a href=\"#rf1-4460\" class=\"backlink\" title=\"Jump back to footnote 1 in the text.\">&#8617;<\/a><\/p><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve just published a rust port of our PrettySize.NET library, now available via cargo and github. Like its .NET predecessor, PrettySize-rs aims to provide a comprehensive API for dealing with file sizes, covering both manipulation and human-readable formatting.<\/p>\n","protected":false},"author":505,"featured_media":4074,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[52,964,11,936],"class_list":["post-4460","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-open-source","tag-prettysize","tag-programming","tag-rust"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"We&#039;ve just published a rust port of our PrettySize.NET library, now available via cargo and github. Like its .NET predecessor, PrettySize-rs aims to provide a comprehensive API for dealing with file sizes, covering both manipulation and human-readable formatting. Before anything else, here&#039;s a quick example: ```rust let bytes = 42 * size::MiB; assert_eq!(bytes, 44040192); let\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Mahmoud Al-Qudsi\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/#article\",\"name\":\"PrettySize for rust | The NeoSmart Files\",\"headline\":\"PrettySize for rust\",\"author\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/author\\\/mqudsi\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/wp-content\\\/uploads\\\/mannequin-size.png\",\"width\":1200,\"height\":1200,\"caption\":\"PrettySize\"},\"datePublished\":\"2018-08-11T15:56:39-05:00\",\"dateModified\":\"2018-08-11T15:56:39-05:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/#webpage\"},\"articleSection\":\"Software, open source, prettysize, programming, rust\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/category\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/category\\\/software\\\/#listItem\",\"position\":2,\"name\":\"Software\",\"item\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/category\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/#listItem\",\"name\":\"PrettySize for rust\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/#listItem\",\"position\":3,\"name\":\"PrettySize for rust\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/category\\\/software\\\/#listItem\",\"name\":\"Software\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#organization\",\"name\":\"The NeoSmart Files\",\"description\":\"Recovery software and more\",\"url\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/author\\\/mqudsi\\\/#author\",\"url\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/author\\\/mqudsi\\\/\",\"name\":\"Mahmoud Al-Qudsi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c2643dd7c6df61aed49d9f3d917ac6d61cafbbda5f9b1619f50d3b749dca415a?s=96&d=mm&r=pg\",\"width\":96,\"height\":96,\"caption\":\"Mahmoud Al-Qudsi\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/#webpage\",\"url\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/\",\"name\":\"PrettySize for rust | The NeoSmart Files\",\"description\":\"We've just published a rust port of our PrettySize.NET library, now available via cargo and github. Like its .NET predecessor, PrettySize-rs aims to provide a comprehensive API for dealing with file sizes, covering both manipulation and human-readable formatting. Before anything else, here's a quick example: ```rust let bytes = 42 * size::MiB; assert_eq!(bytes, 44040192); let\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/author\\\/mqudsi\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/author\\\/mqudsi\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/wp-content\\\/uploads\\\/mannequin-size.png\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/#mainImage\",\"width\":1200,\"height\":1200,\"caption\":\"PrettySize\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/prettysize-for-rust\\\/#mainImage\"},\"datePublished\":\"2018-08-11T15:56:39-05:00\",\"dateModified\":\"2018-08-11T15:56:39-05:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/\",\"name\":\"The NeoSmart Files\",\"description\":\"Recovery software and more\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"PrettySize for rust | The NeoSmart Files","description":"We've just published a rust port of our PrettySize.NET library, now available via cargo and github. Like its .NET predecessor, PrettySize-rs aims to provide a comprehensive API for dealing with file sizes, covering both manipulation and human-readable formatting. Before anything else, here's a quick example: ```rust let bytes = 42 * size::MiB; assert_eq!(bytes, 44040192); let","canonical_url":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/#article","name":"PrettySize for rust | The NeoSmart Files","headline":"PrettySize for rust","author":{"@id":"https:\/\/neosmart.net\/blog\/author\/mqudsi\/#author"},"publisher":{"@id":"https:\/\/neosmart.net\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/neosmart.net\/blog\/wp-content\/uploads\/mannequin-size.png","width":1200,"height":1200,"caption":"PrettySize"},"datePublished":"2018-08-11T15:56:39-05:00","dateModified":"2018-08-11T15:56:39-05:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/#webpage"},"isPartOf":{"@id":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/#webpage"},"articleSection":"Software, open source, prettysize, programming, rust"},{"@type":"BreadcrumbList","@id":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/neosmart.net\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/category\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/category\/software\/#listItem","position":2,"name":"Software","item":"https:\/\/neosmart.net\/blog\/category\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/#listItem","name":"PrettySize for rust"},"previousItem":{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/#listItem","position":3,"name":"PrettySize for rust","previousItem":{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/category\/software\/#listItem","name":"Software"}}]},{"@type":"Organization","@id":"https:\/\/neosmart.net\/blog\/#organization","name":"The NeoSmart Files","description":"Recovery software and more","url":"https:\/\/neosmart.net\/blog\/"},{"@type":"Person","@id":"https:\/\/neosmart.net\/blog\/author\/mqudsi\/#author","url":"https:\/\/neosmart.net\/blog\/author\/mqudsi\/","name":"Mahmoud Al-Qudsi","image":{"@type":"ImageObject","@id":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/c2643dd7c6df61aed49d9f3d917ac6d61cafbbda5f9b1619f50d3b749dca415a?s=96&d=mm&r=pg","width":96,"height":96,"caption":"Mahmoud Al-Qudsi"}},{"@type":"WebPage","@id":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/#webpage","url":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/","name":"PrettySize for rust | The NeoSmart Files","description":"We've just published a rust port of our PrettySize.NET library, now available via cargo and github. Like its .NET predecessor, PrettySize-rs aims to provide a comprehensive API for dealing with file sizes, covering both manipulation and human-readable formatting. Before anything else, here's a quick example: ```rust let bytes = 42 * size::MiB; assert_eq!(bytes, 44040192); let","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/neosmart.net\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/#breadcrumblist"},"author":{"@id":"https:\/\/neosmart.net\/blog\/author\/mqudsi\/#author"},"creator":{"@id":"https:\/\/neosmart.net\/blog\/author\/mqudsi\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/neosmart.net\/blog\/wp-content\/uploads\/mannequin-size.png","@id":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/#mainImage","width":1200,"height":1200,"caption":"PrettySize"},"primaryImageOfPage":{"@id":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/#mainImage"},"datePublished":"2018-08-11T15:56:39-05:00","dateModified":"2018-08-11T15:56:39-05:00"},{"@type":"WebSite","@id":"https:\/\/neosmart.net\/blog\/#website","url":"https:\/\/neosmart.net\/blog\/","name":"The NeoSmart Files","description":"Recovery software and more","inLanguage":"en-US","publisher":{"@id":"https:\/\/neosmart.net\/blog\/#organization"}}]}},"aioseo_meta_data":{"post_id":"4460","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2020-12-23 20:02:31","updated":"2026-01-10 22:17:44","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/neosmart.net\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/neosmart.net\/blog\/category\/software\/\" title=\"Software\">Software<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tPrettySize for rust\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/neosmart.net\/blog\/"},{"label":"Software","link":"https:\/\/neosmart.net\/blog\/category\/software\/"},{"label":"PrettySize for rust","link":"https:\/\/neosmart.net\/blog\/prettysize-for-rust\/"}],"jetpack_shortlink":"https:\/\/wp.me\/p4xDa-19W","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/neosmart.net\/blog\/wp-content\/uploads\/mannequin-size.png","_links":{"self":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/4460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/users\/505"}],"replies":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/comments?post=4460"}],"version-history":[{"count":1,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/4460\/revisions"}],"predecessor-version":[{"id":4461,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/4460\/revisions\/4461"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/media\/4074"}],"wp:attachment":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/media?parent=4460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/categories?post=4460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/tags?post=4460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}