1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! Builder pattern for constructing [`Blob`](libvctrl_handler::Blob) objects.
//!
//! # Purpose
//! This module provides the [`BlobBuilder`], an ergonomic utility for
//! incrementally constructing version control blobs. While a [`Blob`] can be
//! created directly via [`Blob::new`](libvctrl_handler::Blob::new), the builder
//! pattern provides a consistent API across all object types in the system.
//!
//! # Design rationale
//! - **API Consistency**: Complex objects like commits and trees have many
//! fields and benefit greatly from the builder pattern. Providing a builder
//! for blobs ensures a uniform construction experience across the crate.
//! - **Extensibility**: If future versions of the system require pre-processing
//! (like compression) or validation (like checking `MAX_BLOB_SIZE`) before
//! creating a blob, this logic can be added to the builder without breaking
//! the existing `Blob::new` API.
//! - **Ownership Management**: The builder takes ownership of the underlying
//! `Vec<u8>` during the `with_data` phase. When [`build`] is called, the
//! vector is moved into the final [`Blob`] with zero heap allocations.
//!
//! # Internal mechanism
//! The builder holds a private `Vec<u8>`. The [`build`] method consumes the
//! builder and moves the vector directly into a new [`Blob`] instance.
use Blob;
/// A builder for creating [`Blob`](libvctrl_handler::Blob) objects.
///
/// # Purpose
/// Provides a fluent interface for assembling a blob's data before finalizing
/// it into an immutable object.
///
/// # Design rationale
/// Implements the standard builder pattern. It derives [`Default`] so it can
/// be easily instantiated, and [`Debug`] for logging purposes. The `build`
/// method consumes `self`, preventing the reuse of the builder after the data
/// has been moved into the final blob.
///
/// # Examples
///
/// Building a blob with some data:
///
/// ```
/// use libvctrl_core::object::BlobBuilder;
///
/// let blob = BlobBuilder::new()
/// .with_data(b"file content".to_vec())
/// .build();
///
/// assert_eq!(blob.size(), 12);
/// ```
///
/// Building an empty blob using `Default`:
///
/// ```
/// use libvctrl_core::object::BlobBuilder;
///
/// let blob = BlobBuilder::default().build();
/// assert!(blob.is_empty());
/// ```