Commit Graph

46 Commits

Author SHA1 Message Date
Andrew Poelstra 5c56b69eed
Merge rust-bitcoin/rust-bitcoin#2667: Remove deprecated legacy numeric methods
051c358bcb Remove deprecated legacy numeric methods (Divyansh Gupta)

Pull request description:

  As `rustc 1.79.0-nightly (9d79cd5f7 2024-04-05)` is released which solves the issue mentioned , but the release has deperacted legacy numeric methods.
  Thus replaced `u16::max_value()` etc with `u32::MAX` & `core::u16` to directly `u16`.

  fix #2639

ACKs for top commit:
  tcharding:
    ACK 051c358bcb
  apoelstra:
    ACK 051c358bcb thanks! I will remove an equivalent commit from my #2669

Tree-SHA512: c08c856f7f3b281417c29283351eac5e0f75cc1c8d23d9aae58d969219a327b2337fe57932053e53773ebb9dbec04254f90149266b6639a66c5c09f2ad1675ef
2024-04-07 15:15:47 +00:00
Divyansh Gupta 051c358bcb Remove deprecated legacy numeric methods
As `rustc 1.79.0-nightly (9d79cd5f7 2024-04-05)` is released which solves the issue mentioned , but the release has deperacted legacy numeric methods.
Thus replace `u16::max_value()` etc with `u32::MAX` & `core::u16` to directly `u16`.

fix #2639
2024-04-07 01:51:14 +05:30
Tobin C. Harding 3d01146374
Allow needless-borrows-for-generic-args
This lint triggers when parsing a reference to a large struct as a
generic argument, which is wrong.

Allow it crate wide because [subjectively] this lint never warns for
anything useful.
2024-04-02 11:40:41 +11:00
Fmt Bot a565db9fdd 2024-03-31 automated rustfmt nightly 2024-03-31 01:03:18 +00:00
Tobin C. Harding 13ec770f10
io: Bump version to 0.1.2
There have only been two PRs merged that touched the `io` crate since it
as last released. The changes are additive so we can do a pre-0.1 point
release.

In preparation for release bump the version and add a changelog entry.
2024-03-15 06:25:55 +11:00
Liam Aharon b9f7462958
Implement infallible for errors
Creates a new macro `impl_from_infallible`, and applies it to custom
error types in the codebase.

Closes #1222.
2024-03-08 16:48:34 +11:00
Tobin C. Harding 9187bf3a65
Fix new nightly warnings/errors
The latest nightly toolchain introduced a whole bunch of new warnings
and errors, mostly to do with import statements - fix them all.
2024-02-21 14:13:49 +11:00
Tobin C. Harding cf602583bd
io: Bump version to 0.1.1
We attempted to release with the current 0.1.0 version forgetting that
we had previously released an empty crate with that version to reserve
the name on crates.io.

Bump the version to 0.1.1 and release the actual code.
2024-02-18 09:39:28 +11:00
Tobin C. Harding db888fa4cc
io: Remove blanket trait impls
Remove the blanket impls of `Read`, `BufRead`, and `Write`. Replace them
with a set of sane impls.

Note, we add code to the `impl_write` macro to implement both
`crate::Write` and `std::io::Write` when "std" feature is
enabled.

Fix: #2432
2024-02-11 06:46:27 +11:00
Tobin C. Harding f317d87ee6
io: Enable "alloc" from "std"
As is customary in our crates, enable the "alloc" feature from the "std"
feature. This allows simplifying the feature gating.
2024-02-05 11:58:10 +11:00
Tobin C. Harding 1d00d47b32
io: Add Changelog
Done in preparation for an initial v0.1.0 release of the new `io` crate.

Add a changelog file with a brief description of whats in the initial release.
2024-02-05 11:58:10 +11:00
Tobin C. Harding 83397c465c
io: Add documentation to all public types and functions
Add docs for all public types and add a lint to enforce this going
forwards.

Use `allow` attribute in macro, will be fixed as a subsequent patch.
2024-02-05 11:58:10 +11:00
Tobin C. Harding 2810b08b0d
io: Add code comment to feature gate
This feature gate requires a little thought to understand, add a code
comment to save the next guy some clock cycles.
2024-02-05 11:58:10 +11:00
Tobin C. Harding 4cf2bf4b40
io: Make Take::read_to_end public
Currently `Take::read_to_end` is private forcing users to use our
"custom" `read_to_limit`, for seasoned Rust hackers
`foo.take(16).read_to_end(buf)` make be more unsurprising.

Make `read_to_end` public.
2024-02-05 11:58:10 +11:00
Martin Habovstiak 5c15ed5441
CI: Epic overhaul
Re-write the whole CI pipeline.

Co-developed-by: Martin Habovstiak <martin.habovstiak@gmail.com>
2024-02-02 05:57:23 +11:00
Tobin C. Harding 0997382772
io: Enable alloc from std
It is less surprising if the "alloc" feature is enabled from the "std"
feature.

Enable "alloc" in "std" and simplify the feature gating.
2024-01-31 11:32:46 +11:00
Tobin C. Harding ba1166a63b
Make crate level attributes uniform
Make the trait level attributes uniform across all released crates in
the repo. Excludes things that are obviously not needed, eg, bench stuff
if there is not bench code.

- Remove `uninhabited_references` - this is allow by default now.
- Remove `unconditional_recursion` and mark the single false positive we
  have with an `allow`.

Note, this does not add `missing_docs` to the `io` crate. There is an
open PR at the moment to add that along with the required docs.
2024-01-31 11:32:46 +11:00
Tobin C. Harding f29da57ef6
io: Add functions to read to the end of a reader
The `std::io::Read` trait includes `read_to_end` but that method
provides a denial of service attack vector since an unbounded reader
will exhaust all system memory.

Add a method to our `Read` trait called `read_to_limit` that does the
same as `std::io::Read::read_to_end` but with memory exhaustion
protection.

Add a `read_to_end` method on our `Take` trait and call through to it
from the new method on our `Read` trait called `read_to_limit`.
2024-01-17 11:23:06 +11:00
Andrew Poelstra 2073a40c50
Merge rust-bitcoin/rust-bitcoin#2240: Require `BufRead` instead of `Read`
263a8b3603 Require BufRead instead of Read (Tobin C. Harding)
32d68fd1fa io: Add BufRead trait (Tobin C. Harding)

Pull request description:

  Require `BufRead` instead of `Read` for consensus decode trait.

ACKs for top commit:
  Kixunil:
    ACK 263a8b3603
  apoelstra:
    ACK 263a8b3603

Tree-SHA512: 58ad04c7267f9091738463331473bd22b61e6b06a13aec38b3602a369cd8e571d7d1388fd81dd7a0a05f2e8d5a9c35270cd8a918a4fafe636506591ed06a4cb2
2024-01-16 15:16:54 +00:00
Tobin C. Harding 32d68fd1fa
io: Add BufRead trait
Add a `BufRead` trait for types that perform buffered reading.

Implement it for:
- `Take`
- `Cursor`
- `std::io::BufRead` readers
- (in no-std builds) for slice of u8s
2024-01-16 09:11:20 +11:00
Tobin C. Harding d480adaf25
io: Simplify crate docs and add README
Simplify the docs in `lib.rs` and copy them into a minimal README file.
2024-01-06 08:22:36 +11:00
Fmt Bot 5af7727250 2023-12-17 automated rustfmt nightly 2023-12-17 00:59:05 +00:00
Tobin C. Harding b58c235733
io: Make crate MSRV 1.56.1
Same as for `rust-bitcoin`, make the MSRV of the `io` crate Rust 1.56.1
2023-12-13 14:22:01 +11:00
Tobin C. Harding 063dac03bd
Import core::cmp 2023-12-13 14:22:01 +11:00
Tobin C. Harding c038d00bd1
io: Move use statement
Use the newly settled upon policy governing layout for imports.
2023-12-13 14:22:01 +11:00
Tobin C. Harding 21c44df76e
inline sink function 2023-12-13 14:22:00 +11:00
Tobin C. Harding 5610b9a6b6
Remove unnecessary rustdoc
This doc does not document any type, remove it.
2023-12-13 14:22:00 +11:00
Fmt Bot 8e7afe5d4a 2023-12-10 automated rustfmt nightly 2023-12-10 00:58:56 +00:00
Tobin C. Harding b1870656c9
Combine the two Error impl blocks together
We have two impl blocks for `Error`, just squash them together into a
single one.
2023-12-04 06:48:27 +11:00
Tobin C. Harding 82ea4ff31d
Move error code to submodule
Move error code to a private `error` submodule and re-export it at the
crate root.

(Puts private `sealed` module at the bottom of the file i.e., this patch
is strictly a code move but we re-order the code while moving it.)
2023-12-04 06:47:14 +11:00
Tobin C. Harding 67511ed03f
Move no_std above comment
Currently the no_std attribute is below a comment that does not relate
to it. For slightly improved clarity move the attribute above the
comment.
2023-12-04 06:37:46 +11:00
Tobin C. Harding f83d68f246
Add vertical whitespace
Make the `io` crate conform to `rust-bitcoin` code style in regards to
whitespace between functions/types etc.

Whitespace only, no other changes.
2023-12-04 06:37:43 +11:00
apoelstra b7604dd768 2023-12-03 automated rustfmt nightly 2023-12-03 00:58:10 +00:00
Tobin C. Harding 5c0759a390
Inline io module in io crate root
Its not immediately obvious why we nest the whole `io` code in an `io`
submodule within `lib.rs`. As far as I can tell we can inline it and
re-export from `rust-bitcoin` same as we do for our other dependencies.

This change would effect other users of the crate but since the `io`
crate is unreleased this effects no-one except us.
2023-11-28 14:17:14 +11:00
Tobin C. Harding 80fe9b99b2
Move public macros to a separate module
In preparation for inlining the `io` molule, move the public macros to a
private `macros` module.

Includes removal of the public re-export of `std` as `_std` - flaggin
this because I do not understand why it is here in the first place, we
can use `std::io::Write` in code that is feature gated on "std".
2023-11-28 11:43:35 +11:00
apoelstra 1c89e07537 2023-11-26 automated rustfmt nightly 2023-11-26 00:57:53 +00:00
Matt Corallo add371d263 Remove `core2` dependency entirely 2023-11-09 16:46:44 +00:00
Matt Corallo b7dd16da99 [IO] Use our own io::Error type
In order to move towards our own I/O traits in the `rust-bitcoin`
ecosystem, we have to slowly replace our use of the `std` and
`core2` traits.

This is the final step in removing the explicit `core2` dependency
for I/O in no-std - replacing the `io::Error` type with our own.

Sadly the `std::io::Error` type requires `std::error::Error` as a
bound on the inner error, which is rather difficult to duplicate in
a way that allows for mapping to `std` and back.

To take a more general approach, we use bound on any `Debug`
instead.
2023-11-07 17:35:18 +00:00
Matt Corallo 3caaadf9bb [IO] Replace the `io::Cursor` re-export with our own `Cursor` 2023-11-07 17:35:17 +00:00
Matt Corallo 141343edb4 [IO] Move to custom `Read` trait mirroring `std::io::Read`
In order to move towards our own I/O traits in the `rust-bitcoin`
ecosystem, we have to slowly replace our use of the `std` and
`core2` traits.

Here we take the second big step, replacing
`{std,core2}::io::Read` with our own `bitcoin_io::io::Read`. We
provide a blanket impl for our trait for all `std::io::Read`, if
the `std` feature is enabled, allowing users who use their own
streams or `std` streams to call `rust-bitcoin` methods directly.
2023-11-07 05:51:39 +00:00
Matt Corallo 6aa7ccf841 [IO] Replace `std::io::Sink` usage with our own trivial impl 2023-11-07 05:51:36 +00:00
Matt Corallo 7eb5d65bda [IO] Provide a macro which implements `io::Write` for types
With the new `bitcoin_io` library, implementing `io::Write`
manually is somewhat tricky - for `std` users we really want to
provide an `std::io::Write` implementation, however for `no-std`
users we want to implement against our internal trait.

Sadly we cannot provide a blanket implementation of
`std::io::Write` for all types whcih implement our `io::Write`
trait as its an out-of-crate impl.

Instead, we provide a macro which will either implement
`std::io::Write` or our `io::Write` depending on the feature flags
set on `bitcoin_io`.
2023-11-07 05:51:34 +00:00
Matt Corallo ac678bb435 [IO] Move to custom `Write` trait mirroring `std::io::Write`
In order to move towards our own I/O traits in the `rust-bitcoin`
ecosystem, we have to slowly replace our use of the `std` and
`core2` traits.

Here we take the first real step, replacing
`{std,core2}::io::Write` withour own `bitcoin_io::io::Write`. We
provide a blanket impl for our trait for all `std::io::Write`, if
the `std` feature is enabled, allowing users who use their own
streams or `std` streams to call `rust-bitcoin` methods directly.
2023-11-07 05:51:31 +00:00
Matt Corallo 5e0209569c Use `io::sink` rather than our custom `EmptyWrite` utility 2023-11-07 05:50:45 +00:00
Matt Corallo a0ade883b6 [IO] Move io module into selected re-exports
In the coming commits we'll move our `io` module to having its own
implementations of the usual I/O traits and structs. Here we first
move to re-exporting only exactly what we need, allowing us to
whittle the list down from a fixed set.
2023-11-07 05:50:42 +00:00
Matt Corallo 27c7c4e26a Add a `bitcoin_io` crate
In order to support standard (de)serialization of structs, the
`rust-bitcoin` ecosystem uses the standard `std::io::{Read,Write}`
traits. This works great for environments with `std`, however sadly
the `std::io` module has not yet been added to the `core` crate.

Thus, in `no-std`, the `rust-bitcoin` ecosystem has historically
used the `core2` crate to provide copies of the `std::io` module
without any major dependencies. Sadly, its one dependency,
`memchr`, recently broke our MSRV.

Worse, because we didn't want to take on any excess dependencies
for `std` builds, `rust-bitcoin` has had to have
mutually-exclusive `std` and `no-std` builds. This breaks general
assumptions about how features work in Rust, causing substantial
pain for applications far downstream of `rust-bitcoin` crates.

Here, we add a new `bitcoin_io` crate, making it an unconditional
dependency and using its `io` module in the in-repository crates
in place of `std::io` and `core2::io`. As it is not substantial
additional code, the `hashes` io implementations are no longer
feature-gated.

This doesn't actually accomplish anything on its own, only adding
the new crate which still depends on `core2`.
2023-11-07 05:50:42 +00:00