Skip to main content

qubit_fs/metadata/
dir_entry.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! Directory entry model.
11
12use crate::{
13    FileKind,
14    FileMetadata,
15    FsPath,
16};
17
18/// One entry returned by directory listing.
19#[derive(Clone, Debug, PartialEq)]
20pub struct DirEntry {
21    /// Provider-local path of the entry.
22    pub path: FsPath,
23    /// Final path component.
24    pub name: String,
25    /// Provider-neutral resource kind.
26    pub kind: FileKind,
27    /// Optional metadata loaded with the entry.
28    pub metadata: Option<FileMetadata>,
29}
30
31impl DirEntry {
32    /// Creates a directory entry.
33    ///
34    /// # Parameters
35    /// - `path`: Provider-local entry path.
36    /// - `kind`: Provider-neutral resource kind.
37    ///
38    /// # Returns
39    /// New entry with no loaded metadata.
40    #[must_use]
41    pub fn new(path: FsPath, kind: FileKind) -> Self {
42        let name = path.file_name().unwrap_or("").to_owned();
43        Self {
44            path,
45            name,
46            kind,
47            metadata: None,
48        }
49    }
50}