Created
July 8, 2014 15:05
-
-
Save apoelstra/aec063249270f2bf9949 to your computer and use it in GitHub Desktop.
Borrow problem in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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