rustronomy_core/universal_containers.rs
1/*
2 Copyright© 2022 Raúl Wolters(1)
3
4 This file is part of rustronomy-core.
5
6 rustronomy is free software: you can redistribute it and/or modify it under
7 the terms of the European Union Public License version 1.2 or later, as
8 published by the European Commission.
9
10 rustronomy is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE. See the European Union Public License for more details.
13
14 You should have received a copy of the EUPL in an/all official language(s) of
15 the European Union along with rustronomy. If not, see
16 <https://ec.europa.eu/info/european-union-public-licence_en/>.
17
18 (1) Resident of the Kingdom of the Netherlands; agreement between licensor and
19 licensee subject to Dutch law as per article 15 of the EUPL.
20*/
21
22//! This module provides high-level API's for commonly used storage objects
23//! in astronomy, such as Images and Tables. Crates in the rustronomy ecosystem
24//! responsible for encoding/decoding specific file formats (such as [rustronomy-fits](https://github.com/smups/rustronomy-fits))
25//! use the containers defined in this trait to facilitate easy data access and
26//! conversion between storage formats.
27//!
28//! ## Metadata
29//! All storage objects defined in this module may contain metadata represented
30//! as `MetaDataTag`s, which are simple key-value pairs. Some metadata tags are
31//! so commonly used in astronomy (such as a tag for the telescope or author)
32//! that they have already been implemented here. In addition, users can add
33//! their own metadata tags. For more info, see the metadata module.
34
35/* (Module structure)
36 note: module-level documentation is supplied in the modules themselves.
37*/
38mod meta_only;
39mod table;
40
41// Handy re-exports (v0.2.1 and higher)
42pub use meta_only::MetaOnly;
43pub use table::{Col, Table};
44
45// utility for formatting byte sizes
46pub(crate) fn fmt_byte_size(byte_size: usize) -> String {
47 if byte_size <= 1000 {
48 format!("{}B", byte_size)
49 } else if byte_size <= 1_000_000 {
50 format!("{}kB", byte_size / 1000)
51 } else if byte_size <= 1_000_000_000 {
52 format!("{}MB", byte_size / 1_000_000)
53 } else if byte_size <= 1_000_000_000_000 {
54 format!("{}GB", byte_size / 1_000_000_000)
55 } else {
56 format!("{}TB", byte_size / 1_000_000_000_000)
57 }
58}