Order an intent or memory listing by an already-validated key, with id as the tiebreak. `reverse` flips the key, not the tiebreak.
(entries: &mut [VaultEntry], sort: VaultListSort, reverse: bool)
| 855 | /// Order an intent or memory listing by an already-validated key, with id as |
| 856 | /// the tiebreak. `reverse` flips the key, not the tiebreak. |
| 857 | fn sort_listing(entries: &mut [VaultEntry], sort: VaultListSort, reverse: bool) { |
| 858 | use VaultListSort as S; |
| 859 | fn attested_rank(entry: &VaultEntry) -> u8 { |
| 860 | match entry.attested.as_deref() { |
| 861 | Some("fresh") => 0, |
| 862 | Some("stale") => 1, |
| 863 | _ => 2, |
| 864 | } |
| 865 | } |
| 866 | fn verifies_rank(entry: &VaultEntry) -> u8 { |
| 867 | match entry.verifies.as_deref() { |
| 868 | Some("yes") => 0, |
| 869 | Some("no") => 1, |
| 870 | _ => 2, |
| 871 | } |
| 872 | } |
| 873 | // Intents carry their status and kind in `status_label`/`manifest_kind`, |
| 874 | // memories in `memory_status`/`memory_kind`; each entry has one pair. |
| 875 | fn status(entry: &VaultEntry) -> Option<&str> { |
| 876 | entry |
| 877 | .status_label |
| 878 | .as_deref() |
| 879 | .or(entry.memory_status.as_deref()) |
| 880 | } |
| 881 | fn kind(entry: &VaultEntry) -> Option<&str> { |
| 882 | entry |
| 883 | .manifest_kind |
| 884 | .as_deref() |
| 885 | .or(entry.memory_kind.as_deref()) |
| 886 | } |
| 887 | if sort == S::Unspecified { |
| 888 | return; |
| 889 | } |
| 890 | entries.sort_by(|a, b| { |
| 891 | let ord = match sort { |
| 892 | S::Unspecified | S::Id => a.id.cmp(&b.id), |
| 893 | // RFC 3339, so lexical == chronological; newest first. |
| 894 | S::Updated => b.updated_at_label.cmp(&a.updated_at_label), |
| 895 | S::Title => a.title.cmp(&b.title), |
| 896 | S::Status => status(a).cmp(&status(b)), |
| 897 | S::Kind => kind(a).cmp(&kind(b)), |
| 898 | S::About => a.about_count.cmp(&b.about_count), |
| 899 | S::Attested => attested_rank(a).cmp(&attested_rank(b)), |
| 900 | S::Verifies => verifies_rank(a).cmp(&verifies_rank(b)), |
| 901 | }; |
| 902 | if reverse { ord.reverse() } else { ord }.then_with(|| a.id.cmp(&b.id)) |
| 903 | }); |
| 904 | } |
| 905 | |
| 906 | /// The RAW intent attestation sources (the bridge's dual-read inputs): |
| 907 | /// the tracked vault entry (frontmatter + body bytes) and the legacy |
no test coverage detected