Commit Graph

6 Commits

Author SHA1 Message Date
Martin Habovstiak 64f7d2549e Fix wrong newtype APIs
This fixes several API bugs:

* Use `TryFrom` instead of `From` for fallible conversions
* Move byte conversion methods from `impl_array_newtype` to
  `impl_bytes_newtype`
* Add missing trait impls like `AsRef`, `Borrow`, their mutable versions
  and infallible conversions from arrays

Closes #1336
2022-12-23 01:28:17 +01:00
Tobin C. Harding 8c4fa5ec3d Remove into_bytes from impl_array_newtype
All the types that we define with `impl_array_newtype` are
`Copy` so the correct conversion method to get the underlying byte array
is `to_bytes`. We currently provide `into_bytes` as well as `to_bytes`,
with one of them calling `clone` - this is unnecessary and against
convention.

- Remove `into_bytes` and for `to_bytes` just return the inner field.
- Add a method that causes build to fail if `Copy` is not implemented.
2022-11-05 06:57:40 +11:00
Tobin C. Harding 53b681b838 Move const_assert to bitcoin_internals
This is an internal macro, now that we have the `internals` crate put
`const_assert` in it.
2022-10-20 06:15:44 +11:00
Tobin C. Harding 5a8a5ff6c9 Move debug_from_display to bitcoin_internals
This is an internal macro, now that we have the `internals` crate put
`debug_from_display` in it.
2022-10-20 06:15:23 +11:00
Tobin C. Harding a2f08f2bc6 Improve docs on impl_array_newtype macro
Trivial cleanup of docs.
2022-10-20 06:15:13 +11:00
Tobin C. Harding 771cdde282 Move impl_array_newtype to bitcoin_internals
`impl_array_newtype` is an internal macro, move it to a new, ever so
meaningfully named, `macros` module.

Use `#[macro_export]`, no other changes to the macro.
2022-10-20 06:14:59 +11:00