qubit_fs/write/write_precondition.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//! Preconditions for opening and committing writes.
9
10use crate::metadata::ResourceVersion;
11
12/// Version precondition applied to a write operation.
13///
14/// # Examples
15///
16/// ```rust
17/// use qubit_fs::metadata::ResourceVersion;
18/// use qubit_fs::write::WritePrecondition;
19///
20/// let precondition = WritePrecondition::IfMatch(ResourceVersion::new("v1"));
21/// let WritePrecondition::IfMatch(version) = precondition else {
22/// panic!("expected a version match precondition");
23/// };
24/// assert_eq!(version.as_str(), "v1");
25/// ```
26#[derive(Clone, Debug, Default, Eq, PartialEq)]
27pub enum WritePrecondition {
28 /// Do not require a version precondition.
29 #[default]
30 None,
31 /// Require that no destination exists.
32 IfAbsent,
33 /// Require the destination to have the supplied version.
34 IfMatch(
35 /// Resource version that must match the current destination.
36 ResourceVersion,
37 ),
38}