pub fn merge_aspath_as4path(aspath: &AsPath, as4path: &AsPath) -> Option<AsPath> {
        if aspath.count_asns() < as4path.count_asns() {
            return Some(aspath.clone())
        }

        let mut as4iter = as4path.segments.iter();
        let mut as4seg = as4iter.next();
        let mut new_segs: Vec<AsPathSegment> = vec![];
        if as4seg.is_none(){
            new_segs.extend(aspath.segments.clone());
            return Some(AsPath{ segments: new_segs })
        }

        for seg in &aspath.segments {
            let as4seg_unwrapped = as4seg.unwrap();
            if let (AsPathSegment::AsSequence(seq), AsPathSegment::AsSequence(seq4)) = (seg, as4seg_unwrapped) {
                let diff_len = seq.len() - seq4.len();
                let mut new_seq: Vec<Asn> = vec![];
                new_seq.extend(seq.iter().take(diff_len));
                new_seq.extend(seq4);
                new_segs.push(AsPathSegment::AsSequence(new_seq));
            } else {
                new_segs.push(as4seg_unwrapped.clone());
            }
            as4seg = as4iter.next();
        }

        Some(AsPath{ segments: new_segs })
    }
/// Construct AsPath from AS_PATH and AS4_PATH
///
/// https://datatracker.ietf.org/doc/html/rfc6793#section-4.2.3
///    If the number of AS numbers in the AS_PATH attribute is less than the
///    number of AS numbers in the AS4_PATH attribute, then the AS4_PATH
///    attribute SHALL be ignored, and the AS_PATH attribute SHALL be taken
///    as the AS path information.
///
///    If the number of AS numbers in the AS_PATH attribute is larger than
///    or equal to the number of AS numbers in the AS4_PATH attribute, then
///    the AS path information SHALL be constructed by taking as many AS
///    numbers and path segments as necessary from the leading part of the
///    AS_PATH attribute, and then prepending them to the AS4_PATH attribute
///    so that the AS path information has a number of AS numbers identical
///    to that of the AS_PATH attribute.  Note that a valid
///    AS_CONFED_SEQUENCE or AS_CONFED_SET path segment SHALL be prepended
///    if it is either the leading path segment or is adjacent to a path
///    segment that is prepended.


If the number of AS numbers in the AS_PATH attribute is larger than
or equal to the number of AS numbers in the AS4_PATH attribute, then
the AS path information SHALL be constructed by taking as many AS
numbers and path segments as necessary from the leading part of the
AS_PATH attribute, and then prepending them to the AS4_PATH attribute
so that the AS path information has a number of AS numbers identical
to that of the AS_PATH attribute.  Note that a valid
AS_CONFED_SEQUENCE or AS_CONFED_SET path segment SHALL be prepended
if it is either the leading path segment or is adjacent to a path
segment that is prepended.
If the number of AS numbers in the AS_PATH attribute is larger than or equal to the number of AS numbers in the AS4_PATH attribute then the AS path information SHALL be constructed by taking as many AS numbers and path segments as necessary from the leading part of the AS_PATH attribute and then prepending them to the AS4_PATH attribute so that the AS path information has a number of AS numbers identical to that of the AS_PATH attribute . Note that a valid AS_CONFED_SEQUENCE or AS_CONFED_SET path segment SHALL be prepended if it is either the leading path segment or is adjacent to a path segment that is prepended .
pub fn merge_aspath_as4path(aspath: &AsPath, as4path: &AsPath) -> Option<AsPath> {
        if aspath.count_asns() < as4path.count_asns() {
            return Some(aspath.clone())
        }
        let mut as4iter = as4path.segments.iter();
        let mut as4seg = as4iter.next();
        let mut new_segs: Vec<AsPathSegment> = vec![];
        if as4seg.is_none(){
            new_segs.extend(aspath.segments.clone());
            return Some(AsPath{ segments: new_segs })
        }
        for seg in &aspath.segments {
            let as4seg_unwrapped = as4seg.unwrap();
            if let (AsPathSegment::AsSequence(seq), AsPathSegment::AsSequence(seq4)) = (seg, as4seg_unwrapped) {
                let diff_len = seq.len() - seq4.len();
                let mut new_seq: Vec<Asn> = vec![];
                new_seq.extend(seq.iter().take(diff_len));
                new_seq.extend(seq4);
                new_segs.push(AsPathSegment::AsSequence(new_seq));
            } else {
                new_segs.push(as4seg_unwrapped.clone());
            }
            as4seg = as4iter.next();
        }
        Some(AsPath{ segments: new_segs })
    }
pub fn merge_aspath_as4path ( aspath : & AsPath , as4path : & AsPath ) -> Option < AsPath > { if aspath . count_asns ( ) < as4path . count_asns ( ) { return Some ( aspath . clone ( ) ) } let mut as4iter = as4path . segments . iter ( ) ; let mut as4seg = as4iter . next ( ) ; let mut new_segs : Vec < AsPathSegment > = vec ! [ ] ; if as4seg . is_none ( ) { new_segs . extend ( aspath . segments . clone ( ) ) ; return Some ( AsPath { segments : new_segs } ) } for seg in & aspath . segments { let as4seg_unwrapped = as4seg . unwrap ( ) ; if let ( AsPathSegment :: AsSequence ( seq ) , AsPathSegment :: AsSequence ( seq4 ) ) = ( seg , as4seg_unwrapped ) { let diff_len = seq . len ( ) - seq4 . len ( ) ; let mut new_seq : Vec < Asn > = vec ! [ ] ; new_seq . extend ( seq . iter ( ) . take ( diff_len ) ) ; new_seq . extend ( seq4 ) ; new_segs . push ( AsPathSegment :: AsSequence ( new_seq ) ) ; } else { new_segs . push ( as4seg_unwrapped . clone ( ) ) ; } as4seg = as4iter . next ( ) ; } Some ( AsPath { segments : new_segs } ) }
Construct AsPath from AS_PATH and AS4_PATH
https://datatracker.ietf.org/doc/html/rfc6793#section-4.2.3
If the number of AS numbers in the AS_PATH attribute is less than the
number of AS numbers in the AS4_PATH attribute, then the AS4_PATH
attribute SHALL be ignored, and the AS_PATH attribute SHALL be taken
as the AS path information.
Construct AsPath from AS_PATH and AS4_PATH https : // datatracker . ietf . org / doc / html / rfc6793#section - 4 . 2 . 3 If the number of AS numbers in the AS_PATH attribute is less than the number of AS numbers in the AS4_PATH attribute then the AS4_PATH attribute SHALL be ignored and the AS_PATH attribute SHALL be taken as the AS path information .
aspath
&AsPath
as4path
&AsPath
aspath
&AsPath
as4path
&AsPath