davecom / SwiftGraph

A Graph Data Structure in Pure Swift
Apache License 2.0
756 stars 80 forks source link

Make `Graph` conform to `Codable` only when the vertices are `Codable`? #84

Open RJPoelstra opened 9 months ago

RJPoelstra commented 9 months ago

Hi,

Native swift types like Array only conform to Codable when their elements are Codable. It looks like Graph doesn't have any special need for being Codable. Would it be possible to make Graph conform to Codable only when its vertices are? I've a use case where I'm not interested in the Graph being codable and adding conformance to the vertex type would be a lot of work.

davecom commented 9 months ago

That's a good question. I think we already went through attempting to make Codable conditional in an earlier version of Swift but ran into some compiler limitations. I would guess this is possible now.

A couple alternatives you could do for now:

RJPoelstra commented 9 months ago

Thanks for the suggestions. I'll look into them.

Vithanco commented 6 days ago

+1