LCOV - code coverage report
Current view: top level - pageserver/src/virtual_file/owned_buffers_io/util - size_tracking_writer.rs (source / functions) Coverage Total Hit
Test: 050dd70dd490b28fffe527eae9fb8a1222b5c59c.info Lines: 100.0 % 24 24
Test Date: 2024-06-25 21:28:46 Functions: 81.8 % 11 9

            Line data    Source code
       1              : use crate::{context::RequestContext, virtual_file::owned_buffers_io::write::OwnedAsyncWriter};
       2              : use tokio_epoll_uring::{BoundedBuf, IoBuf};
       3              : 
       4              : pub struct Writer<W> {
       5              :     dst: W,
       6              :     bytes_amount: u64,
       7              : }
       8              : 
       9              : impl<W> Writer<W> {
      10         1246 :     pub fn new(dst: W) -> Self {
      11         1246 :         Self {
      12         1246 :             dst,
      13         1246 :             bytes_amount: 0,
      14         1246 :         }
      15         1246 :     }
      16              : 
      17     15158043 :     pub fn bytes_written(&self) -> u64 {
      18     15158043 :         self.bytes_amount
      19     15158043 :     }
      20              : 
      21      4303388 :     pub fn as_inner(&self) -> &W {
      22      4303388 :         &self.dst
      23      4303388 :     }
      24              : 
      25              :     /// Returns the wrapped `VirtualFile` object as well as the number
      26              :     /// of bytes that were written to it through this object.
      27              :     #[cfg_attr(target_os = "macos", allow(dead_code))]
      28            3 :     pub fn into_inner(self) -> (u64, W) {
      29            3 :         (self.bytes_amount, self.dst)
      30            3 :     }
      31              : }
      32              : 
      33              : impl<W> OwnedAsyncWriter for Writer<W>
      34              : where
      35              :     W: OwnedAsyncWriter,
      36              : {
      37              :     #[inline(always)]
      38         6613 :     async fn write_all<B: BoundedBuf<Buf = Buf>, Buf: IoBuf + Send>(
      39         6613 :         &mut self,
      40         6613 :         buf: B,
      41         6613 :         ctx: &RequestContext,
      42         6613 :     ) -> std::io::Result<(usize, B::Buf)> {
      43         6613 :         let (nwritten, buf) = self.dst.write_all(buf, ctx).await?;
      44         6613 :         self.bytes_amount += u64::try_from(nwritten).unwrap();
      45         6613 :         Ok((nwritten, buf))
      46         6613 :     }
      47              : }
        

Generated by: LCOV version 2.1-beta