@@ -96,6 +96,21 @@ impl HopPath {
96
96
self . hops . iter ( ) . any ( |h| h == hop)
97
97
}
98
98
99
+ pub fn contains_segments ( & self ) -> bool {
100
+ self . hops . iter ( ) . any ( |h| if let Hop :: Segment ( _) = h { true } else { false } )
101
+ }
102
+
103
+ pub fn contains_sets ( & self ) -> bool {
104
+ self . hops . iter ( ) . any ( |h| if let Hop :: Segment ( s) = h {
105
+ if s. stype == SegmentType :: Set || s. stype == SegmentType :: ConfedSet {
106
+ true
107
+ } else {
108
+ false }
109
+ } else {
110
+ false }
111
+ )
112
+ }
113
+
99
114
pub fn get_hop ( & self , index : usize ) -> Option < & OwnedHop > {
100
115
self . hops . get ( index)
101
116
}
@@ -261,9 +276,25 @@ impl HopPath {
261
276
} )
262
277
}
263
278
279
+ pub fn try_to_asn32_path < Octs > (
280
+ & self
281
+ ) -> Result < AsPath < Octs > ,
282
+ <<Octs as FromBuilder >:: Builder as OctetsBuilder >:: AppendError
283
+ >
284
+ where
285
+ Octs : FromBuilder ,
286
+ <Octs as FromBuilder >:: Builder : EmptyBuilder
287
+ {
288
+ let mut target = EmptyBuilder :: empty ( ) ;
289
+ Self :: compose_as_path ( & self . hops , & mut target) ?;
290
+ Ok ( unsafe {
291
+ AsPath :: new_unchecked ( Octs :: from_builder ( target) , false )
292
+ } )
293
+ }
294
+
264
295
265
296
// Turn this HopPath into the four-octet based AS_PATH wireformat.
266
- fn compose_as_path < Octs : Octets , Target : OctetsBuilder > (
297
+ pub fn compose_as_path < Octs : Octets , Target : OctetsBuilder > (
267
298
mut hops : & [ Hop < Octs > ] , target : & mut Target
268
299
) -> Result < ( ) , Target :: AppendError > {
269
300
while !hops. is_empty ( ) {
@@ -762,6 +793,7 @@ impl<'a, Octs: Octets> Iterator for PathHops<'a, Octs> {
762
793
//----------- PathSegments ---------------------------------------------------
763
794
764
795
/// Iterates over [`Segment`]s in an [`AsPath`].
796
+ #[ derive( Debug ) ]
765
797
pub struct PathSegments < ' a , Octs > {
766
798
parser : Parser < ' a , Octs > ,
767
799
four_byte_asns : bool ,
0 commit comments