Recognizes a [`SonameV2`], a [`SonameV1`] or a [`PackageRelation`] in a string slice. First attempts to recognize a [`SonameV2`], then a [`SonameV1`] and if that fails, falls back to recognizing a [`PackageRelation`]. Depending on recognized type, a [`RelationOrSoname`] is created accordingly.
(input: &mut &str)
| 66 | // with the most specific and ending with the least specific, generic PackageRelation. |
| 67 | // |
| 68 | // We are forced to use parser_until, as there are some soname expressions, such as |
| 69 | // `libalpm.so>=14` or `librtmp.so.0`, which we only encountered in the AUR until now. |
| 70 | // These expressions however, are picked up by pacman as virtual components and as such, |
| 71 | // we also have to handle these in the same way, even if it's dirty. |
| 72 | let checkpoint = input.checkpoint(); |
| 73 | if let Ok(v2) = SonameV2::parser_until(delimiter.by_ref()) |
| 74 | .map(RelationOrSoname::SonameV2) |
| 75 | .parse_next(input) |
| 76 | { |
| 77 | return Ok(v2); |
| 78 | }; |
| 79 | input.reset(&checkpoint); |
| 80 | |
| 81 | if let Ok(v1) = SonameV1::parser_until(delimiter.by_ref()) |
| 82 | .map(RelationOrSoname::SonameV1) |
| 83 | .parse_next(input) |
| 84 | { |
| 85 | return Ok(v1); |
| 86 | }; |
| 87 | input.reset(&checkpoint); |
| 88 | |
| 89 | PackageRelation::parser_until(delimiter.by_ref()) |
| 90 | .map(RelationOrSoname::Relation) |
| 91 | .parse_next(input) |
| 92 | }; |
| 93 | parser.layer("alpm-package-relation or alpm-sonamev1 or alpm-sonamev2") |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | impl Display for RelationOrSoname { |
| 98 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 99 | match self { |
| 100 | RelationOrSoname::Relation(version) => write!(f, "{version}"), |