beacon-biosignals / StableHashTraits.jl

Compute hashes over any Julia object simply and reproducibly
MIT License
9 stars 3 forks source link

add functionality for custom properties using context #21

Closed acdupont closed 1 year ago

acdupont commented 1 year ago

Add ability for users to specify list of properties to be used when UseProperties.

acdupont commented 1 year ago

This change is a bit awkward with the existing UseProperties because a stable_hash_propertynames can handle all use cases. An alternate implementation could be to add a ignore field to the UseProperties.

haberdashPI commented 1 year ago

I think this is already possible by using transform (but note that the API for this may be changing a bit if #22 merges).

For example

struct MyType
    x::Int
    y::Int
    __priviate::String
end
StableHashTraits.transform(x::MyType) = (; x.x, x.y)

This would exclude the __private field from hashing.

haberdashPI commented 1 year ago

If #22 merges, this would like like the following:

struct MyType
    x::Int
    y::Int
    __priviate::String
end
StableHashTraits.has_method(::MyType) = UseTransform(x -> (; x.x, x.y))
acdupont commented 1 year ago

I ended up using transform as well. Since tranform is more general and covers the use case of this PR, I'm closing it.