Skip to content

Thingbuf Peek / view front #97

@micahcc

Description

@micahcc

I'm writing a socket writer where I won't know how many bytes are consumed until after I've viewed the data.

I have roughly the following:

struct InFlight {
   pos: usize,
   data: Vec<u8>,
}

fn foo() -> Result<()> {
    let buf = Thingbuf<InFlight>::new(10);
   // feed the buf

  loop {
    let next = buf.front_mut(); // this function doesn't exist but I need it
    let sent_bytes = send(next.data[pos..])?;
    next.pos += sent_bytes;

    if next.pos == next.data.len() {
      buf.pop_front();
   }
  }
}

The key here is if I preemptively pop_front() I might not have consumed all the bytes in InFlight yet

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions