Add Uuid Builder #332
No reviewers
Labels
No labels
breaking
bug
dependencies
good first issue
help wanted
unstable
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-uuid-rs/uuid!332
Loading…
Reference in a new issue
No description provided.
Delete branch "master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'm submitting a feature
Description
This PR implements a basic UuidBuilder that takes itself by
&mutinstead ofselfas shown in the issue #171 description.Motivation
Issue #171
Tests
Through Doctests
Related Issue(s)
#171
@ -0,0 +1,295 @@// Copyright 2013-2014 The Rust Project Developers.Let's remove the
Copyimplementation here, because the behaviour ofCopytypes and&mut selfmethods can be surprising.Hi @Veykril 👋
I'm on mobile at the moment so just left a little comment from a quick scan.
I'd be tempted to mark the
from_random_bytesmethod as deprecated now and suggest using this builder type.@ -0,0 +1,295 @@// Copyright 2013-2014 The Rust Project Developers.Oh interesting, I didn't know that this might cause weird behaviour. Will remove it then, this builder doesn't consume itself anyways so there is no need to copy it anyways.
Should I deprecate it with
#[deprecated(since="0.7.2", note="please use theUuidBuilderinstead")]then?I don't think it's a good idea to deprecate we are just giving the users to
use a builder pattern if they want to.
On Tue, Oct 2, 2018, 16:04 Lukas Wirth notifications@github.com wrote:
@ -0,0 +1,295 @@// Copyright 2013-2014 The Rust Project Developers.Actually removing the copy implementation will trigger the
missing_copy_implementationslint.@ -0,0 +1,295 @@// Copyright 2013-2014 The Rust Project Developers.Actually, we should probably go ahead and remove all of those derives besides
Debug, the others don't really make sense for a builder type.We can override that lint with
#[allow(missing_copy_implementations)]alongside this#[derive]attribute.@Dylan-DPC I think
from_random_byteswas really only added specifically to call some of the mutating methods we now have on this builder without exposing them onUuid, which isCopy. I don't think we need to hang on to APIs indefinitely when new approaches emerge, otherwise we could risk winding up with a large API surface area that's difficult to navigate. Pushing users towards theBuilderfor any non-standard initialisation seems like it would be helpful for users trying to find their way around.@KodrAus oops yeah just checked the function again. That's fine by me 👍
@ -0,0 +1,295 @@// Copyright 2013-2014 The Rust Project Developers.Yeh, the wierdness is that a type that implements
Copycan be implicitly copied around, so when you're passing the value around and calling mutating methods you can end up mutating a copy by accident.Alright, I made the proposed changes. Is the version I put into the attribute correct for this?
yep @Veykril that's fine
@ -0,0 +1,295 @@// Copyright 2013-2014 The Rust Project Developers.Ah yes, that makes never though of it like that. That is good thing to keep in mind.
@ -0,0 +1,295 @@// Copyright 2013-2014 The Rust Project Developers.use
uuid::prelude::*where possiblemaybe make this a
newtypetuple? Just to make it consistent with the rest of the cratepub fn build(&self) -> Uuid->pub fn build(self) -> Uuidmaybe have two be/le
from_slicefunctions instead?make the
buildermodulepuband instead of the reexport here, reexport inpreludemodulenote = "useuuid::builder::UuidBuilderinstead"@ -0,0 +1,295 @@// Copyright 2013-2014 The Rust Project Developers.Add the copyright header (copy the one in lib.rs, first few lines)
@ -0,0 +1,295 @@// Copyright 2013-2014 The Rust Project Developers.We could make this method take
&mut self, so that we have the future option to move the internal uuid out instead of copying it.Something about
uuid::builder::UuidBuilderdoesn't sit right with me... We could just go withuuid::Builder?yeah its not like we are going to have several builders so
uuid::Buildershould be fineSo should I reexport the
Builderviapub use builder::Builder;in thelib.rsas well as reexporting it through the prelude?@ -0,0 +1,295 @@// Copyright 2013-2014 The Rust Project Developers.I used
&selfsince that was what was given in the issue example, normally you'd consume the builder when building but since our internal type is copy both works here I'd say. What should I pick?@ -0,0 +1,295 @@// Copyright 2013-2014 The Rust Project Developers.I would go with
&mut selfhere, it's consistent with the other mutating methods we've added, and lets us do some extra work in thebuildmethod if we need it. Using&mut selfoverselfmeans that we can chain the method calls in a single statement like this:If the
buildmethod tookselfby value then we wouldn't be able to chain it withset_version.I think I changed everything that was requested now
@Veykril can fix the build failures and then its good to merge
I dont know what that error message is 😕
@Dylan-DPC @KodrAus ideas?
Oh I think Rust 1.22 doesn't support nested import groups, yeah that feature was added in 1.25.
bors: r+
Build succeeded