Skip to content

Commit f00f353

Browse files
committed
Provide a mechanism for setting the version Option
The `SnapshotBuilder` is a reasonable improvement IMHO, but the fluent style because challenging when the caller has an `Option<u64>` as well. I have been fond of the [AWS SDK fluent builders](https://docs.rs/aws-credential-types/1.2.6/aws_credential_types/struct.CredentialsBuilder.html#method.set_account_id) which provide a `account_id(id)` and `set_account_id(Option<id>)` style builders which give callers flexibility. Instead of: ```rust let mut builder = Snapshot::builder(url); builder = match version.as_ref() { Some(version) => builder.at_version(version), None => builder, }; let snapshot = builder.build(engine.as_ref(); ``` Callers can instead: ```rust let snapshot = Snapshot::builder(url).set_version(version).build(engine.as_ref()); ``` Signed-off-by: R. Tyler Croy <[email protected]>
1 parent 447767e commit f00f353

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

kernel/src/snapshot/builder.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ impl SnapshotBuilder {
4343
self
4444
}
4545

46+
47+
/// Set the `version` [Option] explicitly.
48+
pub fn set_version(mut self, version: Option<Version>) -> Self {
49+
self.version = version;
50+
self
51+
}
52+
4653
/// Create a new [`Snapshot`] instance.
4754
///
4855
/// # Parameters

0 commit comments

Comments
 (0)