Skip to content

Commit d98e49b

Browse files
authored
Reinstate read(::IO,::Type{<:StaticArray}) (#515)
This was removed in the rush to 0.7 compatibility but makes sense for immutable `StaticArray` types.
1 parent 8609799 commit d98e49b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/io.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
@inline function read!(io::IO, ::Type{SA}) where {SA<:StaticArray}
2+
@inline function read(io::IO, ::Type{SA}) where {SA<:StaticArray}
33
elements = Ref{NTuple{length(SA),eltype(SA)}}()
44
read!(io, elements)
55
SA(elements[])
@@ -10,6 +10,8 @@ end
1010
a
1111
end
1212

13+
@deprecate read!(io::IO, SA::Type{<:StaticArray}) read(io, SA)
14+
1315
@inline function write(io::IO, a::SA) where {SA<:StaticArray}
1416
write(io, Ref(Tuple(a)))
1517
end

test/io.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ end
1313
@testset "Binary IO" begin
1414
@testset "read!" begin
1515
# Read static arrays from a stream which was serialized elementwise
16-
@test read!(write_buf(UInt8, 1,2,3), SVector{3,UInt8}) === SVector{3,UInt8}(1,2,3)
17-
@test read!(write_buf(Int32, -1,2,3), SVector{3,Int32}) === SVector{3,Int32}(-1,2,3)
18-
@test read!(write_buf(Float64, 1,2,3), SVector{3,Float64}) === SVector{3,Float64}(1,2,3)
19-
@test read!(write_buf(Float64, 1,2,3,4), SMatrix{2,2,Float64}) === @SMatrix [1.0 3.0; 2.0 4.0]
16+
@test read(write_buf(UInt8, 1,2,3), SVector{3,UInt8}) === SVector{3,UInt8}(1,2,3)
17+
@test read(write_buf(Int32, -1,2,3), SVector{3,Int32}) === SVector{3,Int32}(-1,2,3)
18+
@test read(write_buf(Float64, 1,2,3), SVector{3,Float64}) === SVector{3,Float64}(1,2,3)
19+
@test read(write_buf(Float64, 1,2,3,4), SMatrix{2,2,Float64}) === @SMatrix [1.0 3.0; 2.0 4.0]
2020
end
2121

2222
@testset "write" begin
@@ -33,6 +33,10 @@ end
3333
@test read!(write_buf(Int32, -1,2,3), zeros(MVector{3,Int32})) == MVector{3,Int32}(-1,2,3)
3434
@test read!(write_buf(Float64, 1,2,3), zeros(MVector{3,Float64})) == MVector{3,Float64}(1,2,3)
3535
@test read!(write_buf(Float64, 1,2,3,4), zeros(MMatrix{2,2,Float64})) == @MMatrix [1.0 3.0; 2.0 4.0]
36+
# Test that read! does, in fact, modify an MVector rather than return a copy.
37+
m = zeros(MVector{3,UInt8})
38+
read!(write_buf(UInt8, 1,2,3), m)
39+
@test m == MVector{3,UInt8}(1,2,3)
3640
end
3741
end
3842

0 commit comments

Comments
 (0)