Skip to content

Instantly share code, notes, and snippets.

@apoelstra
Created July 8, 2014 15:05
Show Gist options
  • Save apoelstra/aec063249270f2bf9949 to your computer and use it in GitHub Desktop.
Save apoelstra/aec063249270f2bf9949 to your computer and use it in GitHub Desktop.
Borrow problem in Rust
/// Add a new UTXO to the set
pub fn add_utxo(&mut self, txo: TxOut, txid: Sha256dHash, vout: uint) -> bool {
let txid = txid.as_bitv();
// Construct node if needed
let node = match self.tree.lookup_mut(&txid) {
Some(node) => node,
None => {
self.tree.insert(&txid, UtxoNode { out: vec![] });
// Note: If this fails, it indicates a bug in our program and/or an OOM
// condition. But maybe we should do something better than task failure
// anyway?
self.tree.lookup_mut(&txid).unwrap()
}
};
// Insert the output
node.out.grow_set(vout, &None, Some(txo));
// Return success
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment