From 5ea3f0ac7b01c2538de16753067a7ceff92af442 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Sun, 31 Aug 2025 18:35:55 +0000 Subject: [PATCH] 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` 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)` 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 --- kernel/src/snapshot/builder.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/src/snapshot/builder.rs b/kernel/src/snapshot/builder.rs index 171820a10..650af3df4 100644 --- a/kernel/src/snapshot/builder.rs +++ b/kernel/src/snapshot/builder.rs @@ -43,6 +43,12 @@ impl SnapshotBuilder { self } + /// Set the `version` [Option] explicitly. + pub fn set_version(mut self, version: Option) -> Self { + self.version = version; + self + } + /// Create a new [`Snapshot`] instance. /// /// # Parameters