From 3542803c4eafa23adfaa6b3327e753c1297d1b2c Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 16 Jan 2025 13:35:25 +1100 Subject: [PATCH 1/2] Make Cursor methods const Mirror the `std::io::Cursor` type by making the same methods `const`. --- io/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/io/src/lib.rs b/io/src/lib.rs index 08a6c089dd..c0bda4c974 100644 --- a/io/src/lib.rs +++ b/io/src/lib.rs @@ -201,11 +201,11 @@ pub struct Cursor { impl> Cursor { /// Constructs a new `Cursor` by wrapping `inner`. #[inline] - pub fn new(inner: T) -> Self { Cursor { inner, pos: 0 } } + pub const fn new(inner: T) -> Self { Cursor { inner, pos: 0 } } /// Returns the position read up to thus far. #[inline] - pub fn position(&self) -> u64 { self.pos } + pub const fn position(&self) -> u64 { self.pos } /// Sets the internal position. /// @@ -226,7 +226,7 @@ impl> Cursor { /// /// This is the whole wrapped buffer, including the bytes already read. #[inline] - pub fn get_ref(&self) -> &T { &self.inner } + pub const fn get_ref(&self) -> &T { &self.inner } /// Returns a mutable reference to the inner buffer. /// From 9ef8e294ac81c79f413fbe47372a3f94c926ef12 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 16 Jan 2025 13:35:25 +1100 Subject: [PATCH 2/2] api: Run just check-api --- api/io/all-features.txt | 6 +++--- api/io/alloc-only.txt | 6 +++--- api/io/no-features.txt | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/io/all-features.txt b/api/io/all-features.txt index 17d4ca33d7..8f3698e432 100644 --- a/api/io/all-features.txt +++ b/api/io/all-features.txt @@ -164,6 +164,9 @@ pub bitcoin_io::ErrorKind::TimedOut pub bitcoin_io::ErrorKind::UnexpectedEof pub bitcoin_io::ErrorKind::WouldBlock pub bitcoin_io::ErrorKind::WriteZero +pub const fn bitcoin_io::Cursor::get_ref(&self) -> &T +pub const fn bitcoin_io::Cursor::new(inner: T) -> Self +pub const fn bitcoin_io::Cursor::position(&self) -> u64 pub const fn bitcoin_io::FromStd::new(inner: T) -> Self pub const fn bitcoin_io::ToStd::new(inner: T) -> Self pub const fn bitcoin_io::from_std(std_io: T) -> bitcoin_io::FromStd @@ -232,11 +235,8 @@ pub fn bitcoin_io::Cursor::eq(&self, other: &bitcoin_io::Cursor) -> bool pub fn bitcoin_io::Cursor::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> pub fn bitcoin_io::Cursor::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result pub fn bitcoin_io::Cursor::get_mut(&mut self) -> &mut T -pub fn bitcoin_io::Cursor::get_ref(&self) -> &T pub fn bitcoin_io::Cursor::inner(&self) -> &T pub fn bitcoin_io::Cursor::into_inner(self) -> T -pub fn bitcoin_io::Cursor::new(inner: T) -> Self -pub fn bitcoin_io::Cursor::position(&self) -> u64 pub fn bitcoin_io::Cursor::read(&mut self, buf: &mut [u8]) -> bitcoin_io::Result pub fn bitcoin_io::Cursor::set_position(&mut self, position: u64) pub fn bitcoin_io::Error::cause(&self) -> core::option::Option<&dyn core::error::Error> diff --git a/api/io/alloc-only.txt b/api/io/alloc-only.txt index acd87863d4..e0d9a76e55 100644 --- a/api/io/alloc-only.txt +++ b/api/io/alloc-only.txt @@ -83,6 +83,9 @@ pub bitcoin_io::ErrorKind::TimedOut pub bitcoin_io::ErrorKind::UnexpectedEof pub bitcoin_io::ErrorKind::WouldBlock pub bitcoin_io::ErrorKind::WriteZero +pub const fn bitcoin_io::Cursor::get_ref(&self) -> &T +pub const fn bitcoin_io::Cursor::new(inner: T) -> Self +pub const fn bitcoin_io::Cursor::position(&self) -> u64 pub enum bitcoin_io::ErrorKind pub fn &[u8]::consume(&mut self, amount: usize) pub fn &[u8]::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> @@ -107,11 +110,8 @@ pub fn bitcoin_io::Cursor::eq(&self, other: &bitcoin_io::Cursor) -> bool pub fn bitcoin_io::Cursor::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> pub fn bitcoin_io::Cursor::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result pub fn bitcoin_io::Cursor::get_mut(&mut self) -> &mut T -pub fn bitcoin_io::Cursor::get_ref(&self) -> &T pub fn bitcoin_io::Cursor::inner(&self) -> &T pub fn bitcoin_io::Cursor::into_inner(self) -> T -pub fn bitcoin_io::Cursor::new(inner: T) -> Self -pub fn bitcoin_io::Cursor::position(&self) -> u64 pub fn bitcoin_io::Cursor::read(&mut self, buf: &mut [u8]) -> bitcoin_io::Result pub fn bitcoin_io::Cursor::set_position(&mut self, position: u64) pub fn bitcoin_io::Error::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result diff --git a/api/io/no-features.txt b/api/io/no-features.txt index 15660438bd..3874ee8f7e 100644 --- a/api/io/no-features.txt +++ b/api/io/no-features.txt @@ -81,6 +81,9 @@ pub bitcoin_io::ErrorKind::TimedOut pub bitcoin_io::ErrorKind::UnexpectedEof pub bitcoin_io::ErrorKind::WouldBlock pub bitcoin_io::ErrorKind::WriteZero +pub const fn bitcoin_io::Cursor::get_ref(&self) -> &T +pub const fn bitcoin_io::Cursor::new(inner: T) -> Self +pub const fn bitcoin_io::Cursor::position(&self) -> u64 pub enum bitcoin_io::ErrorKind pub fn &[u8]::consume(&mut self, amount: usize) pub fn &[u8]::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> @@ -103,11 +106,8 @@ pub fn bitcoin_io::Cursor::eq(&self, other: &bitcoin_io::Cursor) -> bool pub fn bitcoin_io::Cursor::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> pub fn bitcoin_io::Cursor::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result pub fn bitcoin_io::Cursor::get_mut(&mut self) -> &mut T -pub fn bitcoin_io::Cursor::get_ref(&self) -> &T pub fn bitcoin_io::Cursor::inner(&self) -> &T pub fn bitcoin_io::Cursor::into_inner(self) -> T -pub fn bitcoin_io::Cursor::new(inner: T) -> Self -pub fn bitcoin_io::Cursor::position(&self) -> u64 pub fn bitcoin_io::Cursor::read(&mut self, buf: &mut [u8]) -> bitcoin_io::Result pub fn bitcoin_io::Cursor::set_position(&mut self, position: u64) pub fn bitcoin_io::Error::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result