Working with our cocina-models can be jarring because, unlike most of the rest of the code we write, dry-structs are immutable which can lead to surprising results when leaning on the usual assignment interactions. So, try something different. What is in this commit (which is partly copypasta from a dry-struct issue) works fine in the simplest use cases (see administrative spec), but currently fails in the gnarlier use cases (file access spec) particularly when reaching into a structure (like a DRO) to modify another structure (like a File). Why? Because File instances are not self-validating. Files are validated in the context of the DRO, and when you reach into the DRO and mutate the File, I have so far not found a way to force a validation in the surrounding context. This feels a lot like working against dry-struct/-types, too, so I am ending the spike and pushing this up for comments.
Working with our cocina-models can be jarring because, unlike most of the rest of the code we write, dry-structs are immutable which can lead to surprising results when leaning on the usual assignment interactions. So, try something different. What is in this commit (which is partly copypasta from a dry-struct issue) works fine in the simplest use cases (see administrative spec), but currently fails in the gnarlier use cases (file access spec) particularly when reaching into a structure (like a DRO) to modify another structure (like a File). Why? Because File instances are not self-validating. Files are validated in the context of the DRO, and when you reach into the DRO and mutate the File, I have so far not found a way to force a validation in the surrounding context. This feels a lot like working against dry-struct/-types, too, so I am ending the spike and pushing this up for comments.