Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: Document order-dependent deserialization of SymbolicRefs
Fintan Halpenny committed 22 days ago
commit e035902a6db8936e21bb1d62af3657df519b3602
parent a8cf4080ce7f4442fa4ad3adc2b907a2fe04d55b
1 file changed +13 -0
modified crates/radicle/src/git/canonical/symbolic.rs
@@ -40,6 +40,19 @@ pub(super) type Target = Unprotected<RefString>;

/// Maintains a cycle-free set of symbolic references.
/// Note that dangling references are not detected.
+
///
+
/// # Deserialization Order
+
///
+
/// Deserialization validates entries in iteration (insertion) order via
+
/// [`TryFrom<IndexMap>`]. This means the validity of a JSON object depends
+
/// on its key order: a symbolic reference whose target is another symbolic
+
/// reference must appear *after* that target in the JSON. For example,
+
/// `{"MAIN": "refs/heads/master", "HEAD": "MAIN"}` is valid, but
+
/// `{"HEAD": "MAIN", "MAIN": "refs/heads/master"}` is not.
+
///
+
/// While JSON objects are nominally unordered (RFC 8259 §4), `serde_json`
+
/// with `IndexMap` preserves insertion order. Any serializer producing
+
/// this JSON must preserve key order for valid round-tripping.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(try_from = "IndexMap<Name, Target>")]
pub struct SymbolicRefs(IndexMap<Name, Target>);