qubit_fs_testkit/async_write_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 asynchronous whole-file write requests.
9
10use qubit_fs::path::Path;
11use qubit_fs::write::WriteOptions;
12
13/// Owned request arguments for an asynchronous write cancellation probe.
14///
15/// Retain these arguments until the borrowed execution future is dropped.
16/// `into_parts` transfers ownership to the driver; the probe can keep an
17/// independent clone for target observation.
18///
19/// # Examples
20///
21/// ```
22/// use qubit_fs::path::Path;
23/// use qubit_fs::write::{WriteDisposition, WriteOptions};
24/// use qubit_fs_testkit::AsyncWriteFixtureCase;
25///
26/// let request = AsyncWriteFixtureCase::new(
27/// Path::parse("/isolated/write-cancel")?,
28/// b"payload".to_vec(),
29/// WriteOptions::default().with_disposition(WriteDisposition::CreateNew),
30/// );
31/// assert_eq!(request.path().as_str(), "/isolated/write-cancel");
32/// assert_eq!(request.bytes(), b"payload");
33/// assert_eq!(request.options().disposition(), WriteDisposition::CreateNew);
34/// let (path, bytes, options) = request.into_parts();
35/// assert_eq!(path.as_str(), "/isolated/write-cancel");
36/// assert_eq!(bytes, b"payload");
37/// assert_eq!(options.disposition(), WriteDisposition::CreateNew);
38/// # Ok::<(), qubit_fs::error::FsError>(())
39/// ```
40#[must_use]
41#[derive(Clone, Debug)]
42pub struct AsyncWriteFixtureCase {
43 /// Destination path passed to the operation.
44 path: Path,
45 /// Owned bytes transferred into the write operation.
46 bytes: Vec<u8>,
47 /// Publication and durability options.
48 options: WriteOptions,
49}
50
51impl AsyncWriteFixtureCase {
52 /// Creates a prepared write request from owned operation arguments.
53 ///
54 /// # Parameters
55 ///
56 /// * `path` - Destination path passed to the operation.
57 /// * `bytes` - Payload transferred into the write operation.
58 /// * `options` - Publication and durability options.
59 ///
60 /// # Returns
61 ///
62 /// A prepared request containing the supplied arguments.
63 #[inline]
64 pub fn new(path: Path, bytes: Vec<u8>, options: WriteOptions) -> Self {
65 Self { path, bytes, options }
66 }
67
68 /// Returns the destination path without transferring ownership.
69 ///
70 /// # Returns
71 ///
72 /// The prepared destination path.
73 #[inline]
74 #[must_use]
75 pub const fn path(&self) -> &Path {
76 &self.path
77 }
78
79 /// Returns the payload without transferring ownership.
80 ///
81 /// # Returns
82 ///
83 /// The prepared payload.
84 #[must_use]
85 #[inline]
86 pub fn bytes(&self) -> &[u8] {
87 &self.bytes
88 }
89
90 /// Returns the write options without transferring ownership.
91 ///
92 /// # Returns
93 ///
94 /// The publication and durability options.
95 #[inline]
96 #[must_use]
97 pub const fn options(&self) -> &WriteOptions {
98 &self.options
99 }
100
101 /// Decomposes the request into owned parts.
102 ///
103 /// # Returns
104 ///
105 /// The destination path, payload, and write options in that order.
106 #[inline]
107 #[must_use]
108 pub fn into_parts(self) -> (Path, Vec<u8>, WriteOptions) {
109 (self.path, self.bytes, self.options)
110 }
111}