Make some std::io functions const

Includes:
- io::Cursor::new
- io::Cursor::get_ref
- io::Cursor::position
- io::empty
- io::repeat
- io::sink
This commit is contained in:
Benoît du Garreau
2020-11-06 17:46:56 +01:00
parent dc06a36074
commit ae059b532f
5 changed files with 28 additions and 7 deletions

View File

@@ -94,7 +94,8 @@ impl<T> Cursor<T> {
/// # force_inference(&buff);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(inner: T) -> Cursor<T> {
#[rustc_const_unstable(feature = "const_io_structs", issue = "none")]
pub const fn new(inner: T) -> Cursor<T> {
Cursor { pos: 0, inner }
}
@@ -130,7 +131,8 @@ impl<T> Cursor<T> {
/// let reference = buff.get_ref();
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_ref(&self) -> &T {
#[rustc_const_unstable(feature = "const_io_structs", issue = "none")]
pub const fn get_ref(&self) -> &T {
&self.inner
}
@@ -175,7 +177,8 @@ impl<T> Cursor<T> {
/// assert_eq!(buff.position(), 1);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn position(&self) -> u64 {
#[rustc_const_unstable(feature = "const_io_structs", issue = "none")]
pub const fn position(&self) -> u64 {
self.pos
}