qubit_fs/spi/stat_response.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.
9//! Provider metadata response.
10
11use crate::metadata::FileMetadata;
12use crate::path::Path;
13
14/// Provider metadata response bound to the path it describes.
15///
16/// # Examples
17///
18/// ```rust
19/// use qubit_fs::metadata::{FileKind, FileMetadata};
20/// use qubit_fs::path::Path;
21/// use qubit_fs::spi::StatResponse;
22///
23/// let response = StatResponse::new(
24/// Path::parse("/object")?,
25/// FileMetadata::new(FileKind::File),
26/// );
27/// assert_eq!("/object", response.path().as_str());
28/// # Ok::<(), qubit_fs::FsError>(())
29/// ```
30pub struct StatResponse {
31 /// Logical path described by the response.
32 path: Path,
33 /// Provider metadata snapshot for `path`.
34 metadata: FileMetadata,
35}
36
37impl StatResponse {
38 /// Creates a response for `path` after provider metadata lookup.
39 ///
40 /// # Parameters
41 /// - `path`: Logical path described by the metadata.
42 /// - `metadata`: Provider metadata snapshot.
43 ///
44 /// # Returns
45 /// A path-bound metadata response.
46 #[inline]
47 #[must_use]
48 pub fn new(path: Path, metadata: FileMetadata) -> Self {
49 Self { path, metadata }
50 }
51
52 /// Returns the logical path represented by the metadata.
53 ///
54 /// # Returns
55 /// The response path.
56 #[inline]
57 #[must_use]
58 pub const fn path(&self) -> &Path {
59 &self.path
60 }
61
62 /// Returns the metadata snapshot.
63 ///
64 /// # Returns
65 /// The provider metadata snapshot.
66 #[inline]
67 #[must_use]
68 pub const fn metadata(&self) -> &FileMetadata {
69 &self.metadata
70 }
71
72 /// Returns the metadata to the validating facade.
73 ///
74 /// # Returns
75 /// The owned provider metadata snapshot.
76 #[inline]
77 #[must_use]
78 pub(crate) fn into_metadata(self) -> FileMetadata {
79 self.metadata
80 }
81}