Skip to main content

disk_core/
lib.rs

1//! The base crate under every rusty-backup filesystem, partition and disk-image crate.
2//!
3//! Always available:
4//! - [`io_other`] / [`repeat_n`]: std shims that build on both current Rust and
5//!   Rust 1.73 (the last toolchain whose std targets macOS 10.7).
6//! - [`display`]: small neutral formatters (sizes, Mac `OSType`, Unix modes).
7//! - [`bits`]: big-endian allocation-bitmap helpers (HFS, HFS+, ProDOS).
8//! - `rust173` (feature `rust173-polyfill` only): extension traits standing in
9//!   for std methods missing on 1.73. Never enable it on a modern toolchain.
10//!
11//! With the `fs` feature (on by default), the interface every filesystem crate
12//! (`fs-8bit`, `fs-mac`, …) implements:
13//! - [`filesystem`]: `Filesystem` (read) and `EditableFilesystem` (write),
14//!   `FilesystemError`, create/repair options.
15//! - [`entry`]: `FileEntry`, `EntryType` and directory display ordering.
16//! - [`fsck`]: integrity-check results shared by every checker.
17//! - [`times`]: Unix timestamps and the calendar conversions filesystems need.
18//! - [`xattr`]: extended-attribute names and values.
19//! - [`unix_common`]: inode, bitmap, compaction and validation helpers shared by Unix-style filesystems.
20//!
21//! Partition and disk-image crates depend on this with `default-features = false`
22//! and so build without the filesystem types and their dependencies.
23
24// `is_multiple_of` & co. come from the rust173 polyfill on 1.73; the real floor check is a 1.73 build.
25#![allow(clippy::incompatible_msrv)]
26
27pub mod bits;
28pub mod display;
29#[cfg(feature = "rust173-polyfill")]
30pub mod rust173;
31
32#[cfg(feature = "fs")]
33pub mod entry;
34#[cfg(feature = "fs")]
35pub mod filesystem;
36#[cfg(feature = "fs")]
37pub mod fsck;
38#[cfg(feature = "fs")]
39pub mod times;
40#[cfg(feature = "fs")]
41pub mod unix_common;
42#[cfg(feature = "fs")]
43pub mod xattr;
44
45/// Construct an `io::Error` of kind `Other` wrapping `error`.
46///
47/// Modern: `io::Error::other` (stable since Rust 1.74). Vintage (1.73): the
48/// equivalent `io::Error::new(ErrorKind::Other, ..)`.
49#[inline]
50pub fn io_other<E>(error: E) -> std::io::Error
51where
52    E: Into<Box<dyn std::error::Error + Send + Sync>>,
53{
54    #[cfg(not(feature = "rust173-polyfill"))]
55    {
56        std::io::Error::other(error)
57    }
58    #[cfg(feature = "rust173-polyfill")]
59    {
60        std::io::Error::new(std::io::ErrorKind::Other, error)
61    }
62}
63
64/// An iterator that repeats `value` exactly `count` times.
65///
66/// Modern: `iter::repeat_n` (stable since Rust 1.87). Vintage (1.73): the
67/// equivalent `iter::repeat(value).take(count)`.
68#[inline]
69pub fn repeat_n<T: Clone>(value: T, count: usize) -> impl Iterator<Item = T> {
70    #[cfg(not(feature = "rust173-polyfill"))]
71    {
72        std::iter::repeat_n(value, count)
73    }
74    #[cfg(feature = "rust173-polyfill")]
75    {
76        std::iter::repeat(value).take(count)
77    }
78}