@@ -68,10 +68,14 @@ impl core::fmt::Display for UdpMetadata {
68
68
impl core:: fmt:: Display for ExtendedUdpMetadata {
69
69
fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
70
70
#[ cfg( feature = "packetmeta-id" ) ]
71
- return write ! ( f, "{}<->{}, PacketID: {:?}" , self . local_endpoint, self . remote_endpoint, self . meta) ;
71
+ return write ! (
72
+ f,
73
+ "{}/{}, PacketID: {:?}" ,
74
+ self . local_endpoint, self . remote_endpoint, self . meta
75
+ ) ;
72
76
73
77
#[ cfg( not( feature = "packetmeta-id" ) ) ]
74
- write ! ( f, "{}" , self . endpoint )
78
+ write ! ( f, "{}/{} " , self . local_endpoint , self . remote_endpoint )
75
79
}
76
80
}
77
81
@@ -372,7 +376,10 @@ impl<'a> Socket<'a> {
372
376
size : usize ,
373
377
meta : impl Into < UdpMetadata > ,
374
378
) -> Result < & mut [ u8 ] , SendError > {
375
- self . send_from ( size, ExtendedUdpMetadata :: new ( self . bound_endpoint ( ) , meta. into ( ) ) )
379
+ self . send_from (
380
+ size,
381
+ ExtendedUdpMetadata :: new ( self . bound_endpoint ( ) , meta. into ( ) ) ,
382
+ )
376
383
}
377
384
378
385
/// Enqueue a packet to be send to a given remote endpoint and pass the buffer
@@ -428,7 +435,11 @@ impl<'a> Socket<'a> {
428
435
where
429
436
F : FnOnce ( & mut [ u8 ] ) -> usize ,
430
437
{
431
- self . send_from_with ( max_size, ExtendedUdpMetadata :: new ( self . bound_endpoint ( ) , meta. into ( ) ) , f)
438
+ self . send_from_with (
439
+ max_size,
440
+ ExtendedUdpMetadata :: new ( self . bound_endpoint ( ) , meta. into ( ) ) ,
441
+ f,
442
+ )
432
443
}
433
444
434
445
/// Enqueue a packet to be sent to a given remote endpoint, and fill it from a slice.
@@ -460,8 +471,7 @@ impl<'a> Socket<'a> {
460
471
///
461
472
/// This function returns `Err(Error::Exhausted)` if the receive buffer is empty.
462
473
pub fn recv_to ( & mut self ) -> Result < ( & [ u8 ] , ExtendedUdpMetadata ) , RecvError > {
463
- let ( meta, payload_buf) =
464
- self . rx_buffer . dequeue ( ) . map_err ( |_| RecvError :: Exhausted ) ?;
474
+ let ( meta, payload_buf) = self . rx_buffer . dequeue ( ) . map_err ( |_| RecvError :: Exhausted ) ?;
465
475
466
476
net_trace ! (
467
477
"udp:{}:{}: receive {} buffered octets" ,
@@ -484,7 +494,10 @@ impl<'a> Socket<'a> {
484
494
/// and return the amount of octets copied as well as the endpoint.
485
495
///
486
496
/// See also [recv](#method.recv).
487
- pub fn recv_slice_to ( & mut self , data : & mut [ u8 ] ) -> Result < ( usize , ExtendedUdpMetadata ) , RecvError > {
497
+ pub fn recv_slice_to (
498
+ & mut self ,
499
+ data : & mut [ u8 ] ,
500
+ ) -> Result < ( usize , ExtendedUdpMetadata ) , RecvError > {
488
501
let ( buffer, endpoint) = self . recv_to ( ) . map_err ( |_| RecvError :: Exhausted ) ?;
489
502
let length = min ( data. len ( ) , buffer. len ( ) ) ;
490
503
data[ ..length] . copy_from_slice ( & buffer[ ..length] ) ;
@@ -496,7 +509,8 @@ impl<'a> Socket<'a> {
496
509
///
497
510
/// See also [recv](#method.recv).
498
511
pub fn recv_slice ( & mut self , data : & mut [ u8 ] ) -> Result < ( usize , UdpMetadata ) , RecvError > {
499
- self . recv_slice_to ( data) . map ( |( length, meta) | ( length, meta. into ( ) ) )
512
+ self . recv_slice_to ( data)
513
+ . map ( |( length, meta) | ( length, meta. into ( ) ) )
500
514
}
501
515
502
516
/// Peek at a packet received from a remote endpoint, and return the endpoint as well
@@ -505,17 +519,18 @@ impl<'a> Socket<'a> {
505
519
///
506
520
/// It returns `Err(Error::Exhausted)` if the receive buffer is empty.
507
521
pub fn peek_to ( & mut self ) -> Result < ( & [ u8 ] , ExtendedUdpMetadata ) , RecvError > {
508
- self . rx_buffer . peek ( ) . map_err ( |_| RecvError :: Exhausted ) . map (
509
- |( meta, payload_buf) | {
522
+ self . rx_buffer
523
+ . peek ( )
524
+ . map_err ( |_| RecvError :: Exhausted )
525
+ . map ( |( meta, payload_buf) | {
510
526
net_trace ! (
511
527
"udp:{}:{}: peek {} buffered octets" ,
512
528
meta. local_endpoint,
513
529
meta. remote_endpoint,
514
530
payload_buf. len( )
515
531
) ;
516
532
( payload_buf, * meta)
517
- } ,
518
- )
533
+ } )
519
534
}
520
535
521
536
/// Peek at a packet received from a remote endpoint, and return the endpoint as well
@@ -533,7 +548,10 @@ impl<'a> Socket<'a> {
533
548
/// This function otherwise behaves identically to [recv_slice](#method.recv_slice).
534
549
///
535
550
/// See also [peek](#method.peek).
536
- pub fn peek_slice_to ( & mut self , data : & mut [ u8 ] ) -> Result < ( usize , ExtendedUdpMetadata ) , RecvError > {
551
+ pub fn peek_slice_to (
552
+ & mut self ,
553
+ data : & mut [ u8 ] ,
554
+ ) -> Result < ( usize , ExtendedUdpMetadata ) , RecvError > {
537
555
let ( buffer, endpoint) = self . peek_to ( ) ?;
538
556
let length = min ( data. len ( ) , buffer. len ( ) ) ;
539
557
data[ ..length] . copy_from_slice ( & buffer[ ..length] ) ;
@@ -547,7 +565,8 @@ impl<'a> Socket<'a> {
547
565
///
548
566
/// See also [peek](#method.peek).
549
567
pub fn peek_slice ( & mut self , data : & mut [ u8 ] ) -> Result < ( usize , UdpMetadata ) , RecvError > {
550
- self . peek_slice_to ( data) . map ( |( length, meta) | ( length, meta. into ( ) ) )
568
+ self . peek_slice_to ( data)
569
+ . map ( |( length, meta) | ( length, meta. into ( ) ) )
551
570
}
552
571
553
572
pub ( crate ) fn accepts ( & self , cx : & mut Context , ip_repr : & IpRepr , repr : & UdpRepr ) -> bool {
0 commit comments