fn write_segment<'a, R: ByteBuffer + ?Sized>(
        &mut self,
        buf: &'a mut [u8],
        mss_reserved: u16,
        seq: Wrapping<u32>,
        ack: Wrapping<u32>,
        flags_after_ns: TcpFlags,
        payload: Option<(&R, usize)>,
    ) -> Result<Incomplete<TcpSegment<'a, &'a mut [u8]>>, WriteNextError> {
        // Write the MSS option on SYNACK segments.
        let mss_option = if flags_after_ns == TcpFlags::SYN | TcpFlags::ACK {
            Some(self.mss)
        } else {
            None
        };

        let segment = TcpSegment::write_incomplete_segment(
            buf,
            seq.0,
            ack.0,
            flags_after_ns,
            self.local_rwnd(),
            mss_option,
            self.mss
                .checked_sub(mss_reserved)
                .ok_or(WriteNextError::MssRemaining)?,
            payload,
        )
        .map_err(WriteNextError::TcpSegment)?;

        if flags_after_ns.intersects(TcpFlags::ACK) {
            self.pending_ack = false;
        }

        Ok(segment)
    }
// The write helper functions return incomplete segments because &self does not have information
// regarding the identity of the endpoints, such as source and destination ports, or source and
// destination L3 addresses (which are required for checksum computation). We need this stupid
// ?Sized trait bound, because otherwise Sized would be implied, and we can have unsized types
// which implement ByteBuffer (such as [u8]), since payload expects a reference to some R.
The write helper functions return incomplete segments because &self does not have information
regarding the identity of the endpoints, such as source and destination ports, or source and
destination L3 addresses (which are required for checksum computation). We need this stupid
?Sized trait bound, because otherwise Sized would be implied, and we can have unsized types
which implement ByteBuffer (such as [u8]), since payload expects a reference to some R.
The write helper functions return incomplete segments because &self does not have information regarding the identity of the endpoints such as source and destination ports or source and destination L3 addresses ( which are required for checksum computation ) . We need this stupid ?Sized trait bound because otherwise Sized would be implied and we can have unsized types which implement ByteBuffer ( such as [ u8 ] ) since payload expects a reference to some R .
fn write_segment<'a, R: ByteBuffer + ?Sized>(
        &mut self,
        buf: &'a mut [u8],
        mss_reserved: u16,
        seq: Wrapping<u32>,
        ack: Wrapping<u32>,
        flags_after_ns: TcpFlags,
        payload: Option<(&R, usize)>,
    ) -> Result<Incomplete<TcpSegment<'a, &'a mut [u8]>>, WriteNextError> {
        // Write the MSS option on SYNACK segments.
        let mss_option = if flags_after_ns == TcpFlags::SYN | TcpFlags::ACK {
            Some(self.mss)
        } else {
            None
        };
        let segment = TcpSegment::write_incomplete_segment(
            buf,
            seq.0,
            ack.0,
            flags_after_ns,
            self.local_rwnd(),
            mss_option,
            self.mss
                .checked_sub(mss_reserved)
                .ok_or(WriteNextError::MssRemaining)?,
            payload,
        )
        .map_err(WriteNextError::TcpSegment)?;
        if flags_after_ns.intersects(TcpFlags::ACK) {
            self.pending_ack = false;
        }
        Ok(segment)
    }
fn write_segment < ' a , R : ByteBuffer + ? Sized > ( & mut self , buf : & ' a mut [ u8 ] , mss_reserved : u16 , seq : Wrapping < u32 > , ack : Wrapping < u32 > , flags_after_ns : TcpFlags , payload : Option < ( & R , usize ) > , ) -> Result < Incomplete < TcpSegment < ' a , & ' a mut [ u8 ] > > , WriteNextError > { // Write the MSS option on SYNACK segments. let mss_option = if flags_after_ns == TcpFlags :: SYN | TcpFlags :: ACK { Some ( self . mss ) } else { None } ; let segment = TcpSegment :: write_incomplete_segment ( buf , seq . 0 , ack . 0 , flags_after_ns , self . local_rwnd ( ) , mss_option , self . mss . checked_sub ( mss_reserved ) . ok_or ( WriteNextError :: MssRemaining ) ? , payload , ) . map_err ( WriteNextError :: TcpSegment ) ? ; if flags_after_ns . intersects ( TcpFlags :: ACK ) { self . pending_ack = false ; } Ok ( segment ) }
The write helper functions return incomplete segments because &self does not have information
regarding the identity of the endpoints, such as source and destination ports, or source and
destination L3 addresses (which are required for checksum computation).
The write helper functions return incomplete segments because &self does not have information regarding the identity of the endpoints such as source and destination ports or source and destination L3 addresses ( which are required for checksum computation ) .
&mut self
buf
&'a mut [u8]
mss_reserved
u16
seq
Wrapping<u32>
ack
Wrapping<u32>
flags_after_ns
TcpFlags
payload
Option<(&R, usize)>
&mut self
buf
&'a mut [u8]
mss_reserved
u16
seq
Wrapping<u32>
ack
Wrapping<u32>
flags_after_ns
TcpFlags
payload
Option<(&R, usize)>