Last active
December 11, 2017 21:26
-
-
Save Killavus/4ff1738f94ec77d63b7807c653056182 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ...snip | |
pub enum ClaimResult<'a> { | |
Claimed(&'a SpawnClaim), | |
ClaimedAlready(&'a SpawnClaim), | |
UnknownSpawn, | |
} | |
// ...snip | |
impl ClaimList { | |
// ...snip | |
fn find_claim(&self, spawn: SpawnItem) -> Option<&SpawnClaim> { | |
self.0.iter().find(|claim| claim.spawn.code == spawn.code) | |
} | |
pub fn claim( | |
&mut self, | |
spawn_list: &SpawnList, | |
spawn_msg: &str, | |
message: Message, | |
) -> ClaimResult { | |
match spawn_list.find_from_msg(spawn_msg) { | |
Some(target_spawn) => { | |
if let Some(claim) = self.find_claim(target_spawn.clone()) { | |
return ClaimResult::ClaimedAlready(claim) | |
} | |
else { | |
self.0.push(SpawnClaim { message, spawn: target_spawn.clone() }); | |
//ClaimResult::Claimed(self.0.iter().last().unwrap()) | |
ClaimResult::UnknownSpawn | |
} | |
}, | |
None => ClaimResult::UnknownSpawn | |
} | |
} | |
} | |
// error[E0502]: cannot borrow `self.0` as mutable because `*self` is also borrowed as immutable | |
// --> src\spawns.rs:89:13 | |
// | | |
// 85 | if let Some(claim) = self.find_claim(target_spawn.clone()) { | |
// | ---- immutable borrow occurs here | |
// ... | |
// 89 | self.0.push(SpawnClaim { message, spawn: target_spawn.clone() }); | |
// | ^^^^^^ mutable borrow occurs here | |
// ... | |
// 96 | } | |
// | - immutable borrow ends here |
This file contains hidden or 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
// ...snip | |
pub enum ClaimResult<'a> { | |
Claimed(&'a SpawnClaim), | |
ClaimedAlready(&'a SpawnClaim), | |
UnknownSpawn, | |
} | |
// ...snip | |
impl ClaimList { | |
// ...snip | |
fn find_claim(&self, spawn: SpawnItem) -> Option<&SpawnClaim> { | |
self.0.iter().find(|claim| claim.spawn.code == spawn.code) | |
} | |
pub fn claim( | |
&mut self, | |
spawn_list: &SpawnList, | |
spawn_msg: &str, | |
message: Message, | |
) -> ClaimResult { | |
match spawn_list.find_from_msg(spawn_msg) { | |
Some(target_spawn) => { | |
{ | |
if let Some(claim) = self.find_claim(target_spawn.clone()) { | |
return ClaimResult::ClaimedAlready(claim) | |
} | |
} | |
self.0.push(SpawnClaim { message, spawn: target_spawn.clone() }); | |
//ClaimResult::Claimed(self.0.iter().last().unwrap()) | |
ClaimResult::UnknownSpawn | |
}, | |
None => ClaimResult::UnknownSpawn | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment