Skip to content

Commit d3e62e7

Browse files
iamed2simeonschaub
authored andcommitted
Add parse method for UUID (JuliaLang#36199)
* Add parse method for UUID * Add test for UUID parse function * [skip ci] Add NEWS for UUID parse function
1 parent e521a6c commit d3e62e7

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Standard library changes
7979

8080
#### UUIDs
8181
* Change `uuid1` and `uuid4` to use `Random.RandomDevice()` as default random number generator ([#35872]).
82+
* Added `parse(::Type{UUID}, ::AbstractString)` method
8283

8384
Deprecated or removed
8485
---------------------

base/uuid.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ function UUID(s::AbstractString)
6969
end
7070
end
7171

72+
parse(::Type{UUID}, s::AbstractString) = UUID(s)
73+
7274

7375
let groupings = [36:-1:25; 23:-1:20; 18:-1:15; 13:-1:10; 8:-1:1]
7476
global string

test/loading.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ let uuidstr = "ab"^4 * "-" * "ab"^2 * "-" * "ab"^2 * "-" * "ab"^2 * "-" * "ab"^6
117117
uuid2 = UUID(uuidstr2)
118118
uuids = [uuid, uuid2]
119119
@test (uuids .== uuid) == [true, false]
120+
121+
@test parse(UUID, uuidstr2) == uuid2
120122
end
121123
@test_throws ArgumentError UUID("@"^4 * "-" * "@"^2 * "-" * "@"^2 * "-" * "@"^2 * "-" * "@"^6)
122124

0 commit comments

Comments
 (0)