ino 0.0.0

I/O traits with special support for POSIX and Linux.
/*
 * Description: I/O traits with special support for POSIX and Linux.
 *
 * Copyright (C) 2025 d@nny mc² <dmc2@amass.energy>
 * SPDX-License-Identifier: AGPL-3.0-or-later
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

/* Ensure any doctest warnings fail the doctest! */
#![doc(test(attr(deny(warnings))))]
/* #![warn(missing_docs)] */
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

//! I/O traits with special support for POSIX and Linux.


use core::mem;

pub trait ReadBuf<T> {
  type E;
  fn read_buf<'buf>(&mut self, buf: &'buf mut [mem::MaybeUninit<T>]) -> (usize, Option<Self::E>);
  #[inline]
  fn read_buf_exact<'buf>(
    &mut self,
    mut buf: &'buf mut [mem::MaybeUninit<T>],
  ) -> Result<(), (usize, Self::E)> {
    let mut all_read: usize = 0;
    while !buf.is_empty() {
      let (cur_read, err) = self.read_buf(buf);
      all_read += cur_read;
      if let Some(err) = err {
        return Err((all_read, err));
      }
      buf = &mut buf[cur_read..];
    }
    Ok(())
  }
}

pub trait ReadBufAtomic<T>: ReadBuf<T> {
  fn read_buf_atomic<'buf>(&mut self, buf: &'buf mut [mem::MaybeUninit<T>]) -> Result<(), Self::E>;
}

pub trait PReadBuf<T> {
  type E;
  fn pread_buf<'buf>(&self, buf: &'buf mut [mem::MaybeUninit<T>]) -> (usize, Option<Self::E>);
}