Remove lifetime mess, replace a lot of code with Arc instead of borrows.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This cleans up the codebase massively, and allows me to maintain some semblance of sanity.
This commit is contained in:
@@ -4,12 +4,12 @@ use crate::dynamic_data::models::pokemon::Pokemon;
|
||||
|
||||
/// A list of Pokemon belonging to a trainer.
|
||||
#[derive(Debug)]
|
||||
pub struct PokemonParty<'pokemon, 'library> {
|
||||
pub struct PokemonParty {
|
||||
/// The underlying list of Pokemon.
|
||||
pokemon: Vec<Option<Arc<Pokemon<'pokemon, 'library>>>>,
|
||||
pokemon: Vec<Option<Arc<Pokemon>>>,
|
||||
}
|
||||
|
||||
impl<'own, 'library> PokemonParty<'own, 'library> {
|
||||
impl<'own, 'library> PokemonParty {
|
||||
/// Instantiates a party with a set size.
|
||||
pub fn new(size: usize) -> Self {
|
||||
let mut pokemon = Vec::with_capacity(size);
|
||||
@@ -20,12 +20,12 @@ impl<'own, 'library> PokemonParty<'own, 'library> {
|
||||
}
|
||||
|
||||
/// Instantiates a party with a list.
|
||||
pub fn new_from_vec(pokemon: Vec<Option<Arc<Pokemon<'own, 'library>>>>) -> Self {
|
||||
pub fn new_from_vec(pokemon: Vec<Option<Arc<Pokemon>>>) -> Self {
|
||||
Self { pokemon }
|
||||
}
|
||||
|
||||
/// Gets a Pokemon at an index in the party.
|
||||
pub fn at(&self, index: usize) -> &Option<Arc<Pokemon<'own, 'library>>> {
|
||||
pub fn at(&self, index: usize) -> &Option<Arc<Pokemon>> {
|
||||
let opt = self.pokemon.get(index);
|
||||
if let Some(v) = opt {
|
||||
v
|
||||
@@ -40,11 +40,7 @@ impl<'own, 'library> PokemonParty<'own, 'library> {
|
||||
}
|
||||
|
||||
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.
|
||||
pub fn swap_into(
|
||||
&mut self,
|
||||
index: usize,
|
||||
pokemon: Option<Arc<Pokemon<'own, 'library>>>,
|
||||
) -> Option<Arc<Pokemon<'own, 'library>>> {
|
||||
pub fn swap_into(&mut self, index: usize, pokemon: Option<Arc<Pokemon>>) -> Option<Arc<Pokemon>> {
|
||||
if index >= self.pokemon.len() {
|
||||
return pokemon;
|
||||
}
|
||||
@@ -69,7 +65,7 @@ impl<'own, 'library> PokemonParty<'own, 'library> {
|
||||
}
|
||||
|
||||
/// Gets the underlying list of Pokemon.
|
||||
pub fn pokemon(&self) -> &Vec<Option<Arc<Pokemon<'own, 'library>>>> {
|
||||
pub fn pokemon(&self) -> &Vec<Option<Arc<Pokemon>>> {
|
||||
&self.pokemon
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user