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