Skip to main content

dope_sys/io/file/
metadata.rs

1use std::num::NonZero;
2
3use crate::io::file::Kind;
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6pub enum Error {
7    Missing(NonZero<u32>),
8    Negative(i64),
9    Overflow(u64),
10}
11
12/// Native metadata for one opened or named file.
13#[derive(Clone, Copy, Debug)]
14pub struct Metadata {
15    kind: Kind,
16    size: i64,
17}
18
19impl Metadata {
20    pub(super) const fn new(raw: libc::stat) -> Self {
21        Self {
22            kind: Kind::from_mode(raw.st_mode),
23            size: raw.st_size,
24        }
25    }
26
27    pub const fn kind(self) -> Kind {
28        self.kind
29    }
30
31    /// Exact signed st_size reported by the native metadata operation.
32    pub const fn size(self) -> i64 {
33        self.size
34    }
35}