cue: support type conversions
Originally opened by @mpvl in https://github.com/cuelang/cue/issues/3
This is a tracking issue for the implementation of the commented out sections in the spec for conversions.
For instance:
- convert between the integer types
- between byte lists and bytes
- etc
But also to convert a struct to a specific struct type. The latter is quite handy for various purposes.
Original reply by @pavel-khritonenko in https://github.com/cuelang/cue/issues/3#issuecomment-527291580
Want to calculate Sha1 checksum and then encode it into Base64 string, but I'm unable to do that, because:
cannot use [164,124,236,58,150,40,5,40,196,175,13,142,106,236,181,44,17,99,146,48] (type list) as string|bytes in argument 2 to encoding/base64.Encode
Original reply by @pavel-khritonenko in https://github.com/cuelang/cue/issues/3#issuecomment-527296143
And in that case, the main root that [Size]byte defined as the return type in crypto/* packages is not being treated as bytes.
Original reply by @mpvl in https://github.com/cuelang/cue/issues/3#issuecomment-527392058
It still makes sense to support conversions, but it probably makes sense to interpret [Size]byte as []byte, and not a list of ints in the first place.
This would be a relatively minor, but breaking change, but presumably a welcome one and I think it is worth it. Feedback welcome.
Original reply by @pavel-khritonenko in https://github.com/cuelang/cue/issues/3#issuecomment-527394325
@mpvl I wondering if there is a working example of crypto/sha1 pkg usage. Cannot imagine where I would like to have [...int] type instead of bytes. I checked all other public packages, only crypto/* packages have such return type.
And it's a definitely different issue than conversion between types.
Original reply by @mpvl in https://github.com/cuelang/cue/issues/3#issuecomment-527498350
I think it is unlikely. We are still in a change where changes can be made if it makes sense (with due consideration of course), but here I think it is obvious.
These APIs were generated before CUE had a bytes type. Now it does, it seems consistent to use it not only for []byte, but also [...]byte.
Original reply by @mpvl in https://github.com/cuelang/cue/issues/3#issuecomment-527499088
I've checked, and such a change in interpretation would only affect the crypto packages.