Builder pattern #171

Closed
opened 2018-03-17 08:17:55 -05:00 by Dylan-DPC-zz · 1 comment
Dylan-DPC-zz commented 2018-03-17 08:17:55 -05:00 (Migrated from github.com)

Description

We're starting to get a lot of potential sources for Uuids and different mutations to apply to them. Something we could look at is adding a builder that can be used to safely mutate a Uuid before handing it back:

// Builder: !Copy
pub struct Builder {
    inner: Uuid,
}

impl Builder {
    fn from_bytes(b: &[u8]) -> Result<Self, ParseError>;
    fn from_uuid_bytes(b: [u8; 16]) -> Self;
    fn nil() -> Self;

    fn set_variant(&mut self, v: UuidVariant) -> &mut Self;
    fn set_version(&mut self, v: UuidVersion) -> &mut Self;

    fn build(&mut self) -> Uuid;
}
let uuid = Builder::from_uuid_bytes(b)
    .set_variant(UuidVariant::RFC4122)
    .set_version(UuidVersion::Random)
    .build();
The builder would probably require some more thought to complement our current set of constructors on Uuid.

Related #170

# Description <!-- Provide a summary of your issue in the Title above --> We're starting to get a lot of potential sources for Uuids and different mutations to apply to them. Something we could look at is adding a builder that can be used to safely mutate a Uuid before handing it back: ```rust // Builder: !Copy pub struct Builder { inner: Uuid, } impl Builder { fn from_bytes(b: &[u8]) -> Result<Self, ParseError>; fn from_uuid_bytes(b: [u8; 16]) -> Self; fn nil() -> Self; fn set_variant(&mut self, v: UuidVariant) -> &mut Self; fn set_version(&mut self, v: UuidVersion) -> &mut Self; fn build(&mut self) -> Uuid; } let uuid = Builder::from_uuid_bytes(b) .set_variant(UuidVariant::RFC4122) .set_version(UuidVersion::Random) .build(); The builder would probably require some more thought to complement our current set of constructors on Uuid. ``` Related #170
kinggoesgaming commented 2018-10-05 12:45:43 -05:00 (Migrated from github.com)

closed in #332

closed in #332
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-uuid-rs/uuid#171
No description provided.