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
//! # Blob Builder
//!
//! This module provides a fluent, ownership-driven builder for constructing
//! [`Blob`] objects. The builder pattern is used because a [`Blob`] is an
//! immutable value object with exactly one required piece of data: the raw
//! content bytes. The builder allows setting that data in a chainable,
//! readable way while deferring validation until the final `build()` call.
use ;
/// A builder for creating [`Blob`] objects.
///
/// `BlobBuilder` provides a safe, ergonomic way to construct a [`Blob`] from a
/// `Vec<u8>` while deferring size validation to the final build step. It is a
/// zero-cost abstraction: after the build, the builder is consumed and the
/// resulting [`Blob`] owns the data with no extra copies.
///
/// # Why this struct exists
///
/// The [`Blob`] constructor `Blob::new` may fail if the supplied data exceeds
/// [`MAX_BLOB_SIZE`](libvctrl_handler::MAX_BLOB_SIZE). A builder delays that
/// fallible operation, allowing callers to accumulate or transform data before
/// finalizing. It also makes construction consistent with other object types
/// that have more fields, providing a uniform API across the crate.
///
/// # How it works
///
/// The builder stores the content in a private `Vec<u8>`. `with_data` replaces
/// that buffer. `build` moves the buffer into `Blob::new`, which performs
/// validation and returns a [`Result`]. After `build`, the builder is consumed
/// and cannot be reused.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// # use libvctrl_core::object::BlobBuilder;
/// let blob = BlobBuilder::new()
/// .with_data(b"file content".to_vec())
/// .build()
/// .unwrap();
///
/// assert_eq!(blob.data(), b"file content");
/// ```