Skip to main content

qubit_fs_testkit/
copy_fixture_case.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//! Provider-prepared synchronous copy fixture cases.
9
10use qubit_fs::copy::CopyOptions;
11use qubit_fs::path::Path;
12
13/// Provider-prepared case that makes one native copy method applicable.
14///
15/// # Examples
16///
17/// ```
18/// use qubit_fs::copy::CopyOptions;
19/// use qubit_fs::path::Path;
20/// use qubit_fs_testkit::CopyFixtureCase;
21///
22/// let source = Path::parse("/source")?;
23/// let target = Path::parse("/target")?;
24/// let case = CopyFixtureCase::new(source, target, CopyOptions::file());
25/// assert_eq!(case.source(), &Path::parse("/source")?);
26/// # Ok::<(), qubit_fs::error::FsError>(())
27/// ```
28#[must_use]
29#[derive(Clone, Debug)]
30pub struct CopyFixtureCase {
31    /// Source path passed to the copy operation.
32    source: Path,
33    /// Destination path passed to the copy operation.
34    target: Path,
35    /// Options that make the native copy method applicable.
36    options: CopyOptions,
37}
38
39impl CopyFixtureCase {
40    /// Creates a native-copy case from its source, target, and requested
41    /// options.
42    ///
43    /// # Parameters
44    ///
45    /// * `source` - Source path passed to the copy operation.
46    /// * `target` - Destination path passed to the copy operation.
47    /// * `options` - Options that make the native method applicable.
48    ///
49    /// # Returns
50    ///
51    /// A prepared case containing the supplied arguments.
52    #[inline]
53    pub fn new(source: Path, target: Path, options: CopyOptions) -> Self {
54        Self {
55            source,
56            target,
57            options,
58        }
59    }
60
61    /// Returns the prepared source path without transferring ownership.
62    ///
63    /// # Returns
64    ///
65    /// The prepared source path.
66    #[inline]
67    #[must_use]
68    pub const fn source(&self) -> &Path {
69        &self.source
70    }
71
72    /// Returns the prepared target path without transferring ownership.
73    ///
74    /// # Returns
75    ///
76    /// The prepared destination path.
77    #[inline]
78    #[must_use]
79    pub const fn target(&self) -> &Path {
80        &self.target
81    }
82
83    /// Returns the options that make the case applicable.
84    ///
85    /// # Returns
86    ///
87    /// The prepared copy options.
88    #[inline]
89    #[must_use]
90    pub const fn options(&self) -> &CopyOptions {
91        &self.options
92    }
93
94    /// Decomposes the case into its owned request parts.
95    ///
96    /// # Returns
97    ///
98    /// The source path, destination path, and copy options in that order.
99    #[inline]
100    #[must_use]
101    pub fn into_parts(self) -> (Path, Path, CopyOptions) {
102        (self.source, self.target, self.options)
103    }
104}