@@ -137,8 +137,9 @@ pub struct MpReachNlri<T: AsRef<[u8]>> {
137
137
}
138
138
139
139
140
- #[ derive( Clone , PartialEq ) ]
141
- pub struct PathAttributes < ' pa , ' sc , ASL > {
140
+ #[ derive( Clone , Debug , PartialEq ) ]
141
+ //pub struct PathAttributes<'pa, 'sc, ASL, T: 'pa + AsRef<[u8]>>{
142
+ pub struct PathAttributes < ' sc , ASL , T : AsRef < [ u8 ] > > {
142
143
asl : std:: marker:: PhantomData :: < ASL > ,
143
144
// XXX perhaps session_config should not live here
144
145
// - 'stand alone path attributes' (i.e., stored in the store or on disk)
@@ -149,16 +150,16 @@ pub struct PathAttributes<'pa, 'sc, ASL>{
149
150
// - if we really want a stand alone owned version of things, a classic
150
151
// PduParseInfo (Copy) should suffice
151
152
session_config : Cow <' sc, SessionConfig >,
152
- raw : Cow < ' pa , [ u8 ] > ,
153
- }
154
- impl < ' pa , ' sc , ASL > std:: fmt:: Debug for PathAttributes < ' pa , ' sc , ASL > {
155
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
156
- match self . raw {
157
- Cow :: Borrowed ( _) => f. write_str ( "borrowed" ) ,
158
- Cow :: Owned ( _) => f. write_str ( "owned" ) ,
159
- }
160
- }
153
+ raw : T ,
161
154
}
155
+ //impl<'sc, ASL, T: AsRef<[u8]>> std::fmt::Debug for PathAttributes<'sc, ASL, T> {
156
+ // fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
157
+ // match self.raw {
158
+ // Cow::Borrowed(_) => f.write_str("borrowed"),
159
+ // Cow::Owned(_) => f.write_str("owned"),
160
+ // }
161
+ // }
162
+ //}
162
163
163
164
/// Overlay/cache over immutable PathAttributes
164
165
///
@@ -171,8 +172,8 @@ impl<'pa, 'sc, ASL> std::fmt::Debug for PathAttributes<'pa, 'sc, ASL> {
171
172
/// XXX: Option<Range<usize>> vs Option<RawAttribute> vs Option<ProperType> ?
172
173
/// Perhaps this thing can double as a builder if we go Option<Cow<_>> ?
173
174
#[ derive( Debug ) ]
174
- pub struct PathAttributesOverlay < ' pa , ' sc , ASL > {
175
- path_attributes : & ' pa PathAttributes < ' pa , ' sc , ASL > ,
175
+ pub struct PathAttributesOverlay < ' pa , ' sc , ASL , T : AsRef < [ u8 ] > > {
176
+ path_attributes : & ' pa PathAttributes < ' sc , ASL , T > ,
176
177
updated : bool ,
177
178
origin : Option < Cow < ' pa , [ u8 ] > > ,
178
179
communities : Option < Cow < ' pa , [ u8 ] > > ,
@@ -181,8 +182,8 @@ pub struct PathAttributesOverlay<'pa, 'sc, ASL> {
181
182
//...
182
183
//...
183
184
}
184
- impl < ' pa , ' sc : ' pa , ASL : ' pa > PathAttributesOverlay < ' pa , ' sc , ASL > {
185
- pub fn for_unchecked ( path_attributes : & ' pa PathAttributes < ' pa , ' sc , ASL > ) -> Self {
185
+ impl < ' pa , ' sc : ' pa , ASL : ' pa , T : AsRef < [ u8 ] > > PathAttributesOverlay < ' pa , ' sc , ASL , T > {
186
+ pub fn for_unchecked ( path_attributes : & ' pa PathAttributes < ' sc , ASL , T > ) -> Self {
186
187
let mut origin = None ;
187
188
let mut communities = None ;
188
189
for raw in path_attributes. iter ( ) {
@@ -243,7 +244,7 @@ impl<'pa, 'sc: 'pa, ASL: 'pa> PathAttributesOverlay<'pa, 'sc, ASL> {
243
244
}
244
245
}
245
246
246
- pub fn owned ( & self ) -> PathAttributes < ' pa , ' sc , ASL > {
247
+ pub fn owned ( & self ) -> PathAttributes < ' sc , ASL , Vec < u8 > > {
247
248
self . path_attributes . owned ( )
248
249
}
249
250
}
@@ -266,10 +267,10 @@ impl<'pa, 'sc: 'pa, ASL: 'pa> PathAttributesOverlay<'pa, 'sc, ASL> {
266
267
// XXX here, we lack compile time checks of whether all fields in the overlay
267
268
// are actually checked and written to the returned Vec.
268
269
// declarative macros are not going to save us, I suppose.
269
- impl < ' pa , ' sc , ASL > From < & PathAttributesOverlay < ' pa , ' sc , ASL > > for Vec < u8 > {
270
- fn from ( pao : & PathAttributesOverlay < ' pa , ' sc , ASL > ) -> Self {
270
+ impl < ' pa , ' sc , ASL , T : AsRef < [ u8 ] > > From < & PathAttributesOverlay < ' pa , ' sc , ASL , T > > for Vec < u8 > {
271
+ fn from ( pao : & PathAttributesOverlay < ' pa , ' sc , ASL , T > ) -> Self {
271
272
if !pao. updated {
272
- return pao. path_attributes . raw . to_vec ( ) ;
273
+ return pao. path_attributes . raw . as_ref ( ) . to_vec ( ) ;
273
274
}
274
275
let mut res = Vec :: new ( ) ;
275
276
if let Some ( raw) = pao. origin . as_ref ( ) {
@@ -285,65 +286,63 @@ impl<'pa, 'sc, ASL> From<&PathAttributesOverlay<'pa, 'sc, ASL>> for Vec<u8> {
285
286
}
286
287
}
287
288
288
- impl < ' pa , ' sc , ASL > From < PathAttributesOverlay < ' pa , ' sc , ASL > > for Vec < u8 > {
289
- fn from ( pao : PathAttributesOverlay < ' pa , ' sc , ASL > ) -> Self {
289
+ impl < ' pa , ' sc , ASL , T : AsRef < [ u8 ] > > From < PathAttributesOverlay < ' pa , ' sc , ASL , T > > for Vec < u8 > {
290
+ fn from ( pao : PathAttributesOverlay < ' pa , ' sc , ASL , T > ) -> Self {
290
291
( & pao) . into ( )
291
292
}
292
293
}
293
294
294
295
295
296
296
- impl < ' pa , ' sc , ASL > PathAttributes < ' pa , ' sc , ASL > {
297
- pub fn owned ( & self ) -> PathAttributes < ' pa , ' sc , ASL > {
297
+ impl < ' sc , ASL , T : AsRef < [ u8 ] > > PathAttributes < ' sc , ASL , T > {
298
+ pub fn owned ( & self ) -> PathAttributes < ' sc , ASL , Vec < u8 > > {
298
299
PathAttributes {
299
300
asl : std:: marker:: PhantomData :: < ASL > ,
300
301
session_config : self . session_config . clone ( ) ,
301
- raw : self . raw . clone ( ) ,
302
+ raw : self . raw . as_ref ( ) . to_vec ( )
302
303
}
303
304
}
304
305
}
305
306
306
- impl < ' pa , ' sc , ASL > From < & PathAttributes < ' pa , ' sc , ASL > > for Vec < u8 > {
307
- fn from ( pas : & PathAttributes < ' pa , ' sc , ASL > ) -> Self {
308
- pas. raw . to_vec ( )
307
+ impl < ' pa , ' sc , ASL , T : AsRef < [ u8 ] > > From < & PathAttributes < ' sc , ASL , T > > for Vec < u8 > {
308
+ fn from ( pas : & PathAttributes < ' sc , ASL , T > ) -> Self {
309
+ pas. raw . as_ref ( ) . to_vec ( )
309
310
}
310
311
}
311
- impl < ' pa , ' sc , ASL > From < PathAttributes < ' pa , ' sc , ASL > > for Vec < u8 > {
312
- fn from ( pas : PathAttributes < ' pa , ' sc , ASL > ) -> Self {
313
- pas. raw . to_vec ( )
312
+ impl < ' sc , ASL , T : AsRef < [ u8 ] > > From < PathAttributes < ' sc , ASL , T > > for Vec < u8 > {
313
+ fn from ( pas : PathAttributes < ' sc , ASL , T > ) -> Self {
314
+ pas. raw . as_ref ( ) . to_vec ( )
314
315
}
315
316
}
316
- impl < ' pa , ' sc , ASL > From < Vec < u8 > > for PathAttributes < ' pa , ' sc , ASL > {
317
+ impl < ' sc , ASL > From < Vec < u8 > > for PathAttributes < ' sc , ASL , Vec < u8 > > {
317
318
fn from ( raw : Vec < u8 > ) -> Self {
318
319
PathAttributes {
319
320
asl : std:: marker:: PhantomData :: < ASL > ,
320
321
session_config : Cow :: Owned ( SessionConfig :: modern ( ) ) ,
321
- raw : Cow :: Owned ( raw ) ,
322
+ raw,
322
323
}
323
324
}
324
325
}
325
326
326
- impl < ' pa , ' sc > PathAttributes < ' pa , ' sc , FourByteAsns > {
327
-
327
+ impl < ' pa , ' sc > PathAttributes < ' sc , FourByteAsns , Vec < u8 > > {
328
328
pub fn modern ( ) -> Self {
329
329
PathAttributes {
330
330
asl : std:: marker:: PhantomData :: < FourByteAsns > ,
331
331
session_config : Cow :: Owned ( SessionConfig :: modern ( ) ) ,
332
- raw : Cow :: Owned ( Vec :: new ( ) )
332
+ raw : Vec :: new ( )
333
333
}
334
334
}
335
335
}
336
336
337
- impl < ' pa , ' sc , ASL > PathAttributes < ' pa , ' sc , ASL > {
338
-
337
+ impl < ' sc , ASL > PathAttributes < ' sc , ASL , Vec < u8 > > {
339
338
pub fn append_unchecked < PA : ToWireformat > ( & mut self , pa : PA ) {
340
- pa. write ( self . raw . to_mut ( ) ) ;
339
+ pa. write ( & mut self . raw ) ;
341
340
}
342
341
}
343
342
344
343
345
- pub struct PathAttributesIter < ' pa , ' sc , ASL > {
346
- raw_attributes : & ' pa PathAttributes < ' pa , ' sc , ASL > ,
344
+ pub struct PathAttributesIter < ' pa , ' sc , ASL , T : AsRef < [ u8 ] > > {
345
+ raw_attributes : & ' pa PathAttributes < ' sc , ASL , T > ,
347
346
idx : usize ,
348
347
}
349
348
@@ -391,7 +390,7 @@ impl<'a> RawAttribute<&'a [u8]> {
391
390
}
392
391
}
393
392
394
- impl < ' pa , ' sc , ASL > Iterator for PathAttributesIter < ' pa , ' sc , ASL > {
393
+ impl < ' pa , ' sc , ASL , T : AsRef < [ u8 ] > > Iterator for PathAttributesIter < ' pa , ' sc , ASL , T > {
395
394
type Item = RawAttribute < & ' pa [ u8 ] > ;
396
395
fn next ( & mut self ) -> Option < Self :: Item > {
397
396
if self . idx == self . raw_attributes . raw . as_ref ( ) . len ( ) {
@@ -420,18 +419,18 @@ impl<'pa, 'sc, ASL> Iterator for PathAttributesIter<'pa, 'sc, ASL> {
420
419
}
421
420
}
422
421
423
- impl < ' pa , ' sc > PathAttributes < ' pa , ' sc , FourByteAsns > {
424
- pub fn new ( raw : impl Into < Cow < ' pa , [ u8 ] > > , session_config : & ' sc SessionConfig ) -> Self {
422
+ impl < ' pa , ' sc , T : AsRef < [ u8 ] > > PathAttributes < ' sc , FourByteAsns , T > {
423
+ pub fn new ( raw : T , session_config : & ' sc SessionConfig ) -> Self {
425
424
Self {
426
425
asl : std:: marker:: PhantomData ,
427
426
session_config : Cow :: Borrowed ( session_config) ,
428
- raw : raw . into ( )
427
+ raw,
429
428
}
430
429
431
430
}
432
431
}
433
- impl < ' pa , ' sc > PathAttributes < ' pa , ' sc , TwoByteAsns > {
434
- pub fn legacy ( raw : impl Into < Cow < ' pa , [ u8 ] > > , session_config : & ' sc SessionConfig ) -> Self {
432
+ impl < ' sc , T : AsRef < [ u8 ] > > PathAttributes < ' sc , TwoByteAsns , T > {
433
+ pub fn legacy ( raw : T , session_config : & ' sc SessionConfig ) -> Self {
435
434
Self {
436
435
asl : std:: marker:: PhantomData ,
437
436
session_config : Cow :: Borrowed ( session_config) ,
@@ -441,8 +440,8 @@ impl<'pa, 'sc> PathAttributes<'pa, 'sc, TwoByteAsns> {
441
440
}
442
441
}
443
442
444
- impl < ' pa , ' sc , ASL > PathAttributes < ' pa , ' sc , ASL > {
445
- pub fn iter ( & self ) -> PathAttributesIter < ASL > {
443
+ impl < ' pa , ' sc , ASL , T : AsRef < [ u8 ] > > PathAttributes < ' sc , ASL , T > {
444
+ pub fn iter ( & self ) -> PathAttributesIter < ASL , T > {
446
445
PathAttributesIter {
447
446
raw_attributes : self ,
448
447
idx : 0
@@ -458,7 +457,7 @@ impl<'pa, 'sc, ASL> PathAttributes<'pa, 'sc, ASL> {
458
457
// Not sure whether that's actually worth it...
459
458
//
460
459
// And ideally, we can specify an order, e.g. by typecode.
461
- pub fn pure_mp_attributes ( & self ) -> Option < PathAttributes < ' pa , ' sc , ASL > > {
460
+ pub fn pure_mp_attributes ( & self ) -> Option < PathAttributes < ' sc , ASL , Vec < u8 > > > {
462
461
self . get_by_type_code ( MpReachNlri :: TYPECODE ) ?;
463
462
464
463
let mut res = Vec :: with_capacity ( self . raw . as_ref ( ) . len ( ) ) ;
@@ -471,20 +470,20 @@ impl<'pa, 'sc, ASL> PathAttributes<'pa, 'sc, ASL> {
471
470
Some ( PathAttributes {
472
471
asl : std:: marker:: PhantomData ,
473
472
session_config : self . session_config . clone ( ) ,
474
- raw : res. into ( )
473
+ raw : res,
475
474
} )
476
475
}
477
476
}
478
477
479
- impl < ' pa , ' sc > PathAttributes < ' pa , ' sc , FourByteAsns > {
478
+ impl < ' pa , ' sc , T : AsRef < [ u8 ] > > PathAttributes < ' sc , FourByteAsns , T > {
480
479
pub fn get_aspath ( & ' pa self ) -> Option < AsPath < FourByteAsns , & ' pa [ u8 ] > > {
481
480
self . get_by_type_code ( PathAttributeType :: AsPath ) . and_then ( |raw|
482
481
AsPath :: < FourByteAsns , & [ u8 ] > :: try_from_raw ( raw) . ok ( )
483
482
)
484
483
}
485
484
}
486
485
487
- impl < ' pa , ' sc , ASL > PathAttributes < ' pa , ' sc , ASL > {
486
+ impl < ' pa , ' sc , ASL , T : AsRef < [ u8 ] > > PathAttributes < ' sc , ASL , T > {
488
487
/// Returns `Some(PA)` if it exists and is valid, otherwise returns None.
489
488
pub fn get_lossy < PA : ' pa + Wireformat < ' pa > + TryFromRaw < ' pa > > ( & ' pa self ) -> Option < PA > {
490
489
self . get_by_type_code ( PA :: TYPECODE ) . and_then ( |raw|
@@ -501,13 +500,13 @@ impl<'pa, 'sc, ASL> PathAttributes<'pa, 'sc, ASL> {
501
500
502
501
//------------ Test with fake Update msg --------------------------------------
503
502
504
- struct UpdateMsg < ' pa , ' sc , ASL > {
505
- path_attributes : PathAttributes < ' pa , ' sc , ASL > ,
503
+ struct UpdateMsg < ' sc , ASL , T : AsRef < [ u8 ] > > {
504
+ path_attributes : PathAttributes < ' sc , ASL , T > ,
506
505
session_config : & ' sc SessionConfig ,
507
506
}
508
507
509
- impl < ' pa , ' sc , ASL > UpdateMsg < ' pa , ' sc , ASL > {
510
- pub fn path_attributes ( & self ) -> & PathAttributes < ' pa , ' sc , ASL > {
508
+ impl < ' sc , ASL , T : AsRef < [ u8 ] > > UpdateMsg < ' sc , ASL , T > {
509
+ pub fn path_attributes ( & self ) -> & PathAttributes < ' sc , ASL , T > {
511
510
& self . path_attributes
512
511
}
513
512
@@ -535,7 +534,7 @@ macro_rules! validate_match {
535
534
536
535
macro_rules! validate_for_asl {
537
536
( $asl: ident) => {
538
- impl <' pa , ' sc> PathAttributes <' pa , ' sc, $asl> {
537
+ impl <' sc , T : AsRef < [ u8 ] >> PathAttributes <' sc, $asl, T > {
539
538
pub fn validate( & self , level: ValidationLevel ) -> bool {
540
539
use PathAttributeType as PAT ;
541
540
self . iter( ) . all( |raw|{
@@ -1016,7 +1015,7 @@ mod tests {
1016
1015
1017
1016
let raw = Vec :: < u8 > :: from ( pas. clone ( ) ) ;
1018
1017
1019
- let pas_again = PathAttributes :: < FourByteAsns > :: from ( raw) ;
1018
+ let pas_again = PathAttributes :: < FourByteAsns , _ > :: from ( raw) ;
1020
1019
assert_eq ! ( pas. owned( ) , pas_again. owned( ) ) ;
1021
1020
1022
1021
}
@@ -1028,7 +1027,7 @@ mod tests {
1028
1027
pas. append_unchecked ( OwnedCommunities ( vec ! [ Community ( 10 ) , Community ( 11 ) ] ) ) ;
1029
1028
let raw = Vec :: < u8 > :: from ( pas. clone ( ) ) ;
1030
1029
// TODO impl From<&pas> for Vec<u8>> let raw = Vec::<u8>::from(&pas);
1031
- let pas2 = PathAttributes :: < FourByteAsns > :: from ( raw) ;
1030
+ let pas2 = PathAttributes :: < FourByteAsns , _ > :: from ( raw) ;
1032
1031
let mut overlay = PathAttributesOverlay :: for_unchecked ( & pas2) ;
1033
1032
1034
1033
// Everything is the same
0 commit comments