From d5df9d4d30ef290ca0a269a9f52f482e284a606a Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Wed, 14 Apr 2021 02:12:18 -0500 Subject: [PATCH] fix: improve type signatures of some methods --- examples/ten_pull.rs | 6 +++--- src/banner.rs | 6 +++--- src/gacha.rs | 11 ++++++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/examples/ten_pull.rs b/examples/ten_pull.rs index 2da3962..49d3e05 100644 --- a/examples/ten_pull.rs +++ b/examples/ten_pull.rs @@ -37,15 +37,15 @@ fn main() { let gacha = GachaBuilder::new(ONE_STAR_RATE, TWO_STAR_RATE, THREE_STAR_RATE) .with_pool(students) - .with_priority(&priority) + .with_priority(priority) .finish() .unwrap(); // I'm some N5 loser don't judge too hard pls... let banner = BannerBuilder::new("不運ですね。") .with_name_translation(Language::English, "Unlucky, right?") - .with_sparkable_students(&sparkable) - .with_gacha(&gacha) + .with_sparkable_students(sparkable) + .with_gacha(gacha) .finish() .unwrap(); diff --git a/src/banner.rs b/src/banner.rs index b87e407..fc6b245 100644 --- a/src/banner.rs +++ b/src/banner.rs @@ -65,9 +65,9 @@ impl BannerBuilder { /// let banner_builder = BannerBuilder::new("ピックアップ募集") /// .with_gacha(&gacha); /// ``` - pub fn with_gacha(self, gacha: &Gacha) -> Self { + pub fn with_gacha(self, gacha: Gacha) -> Self { Self { - gacha: Some(gacha.to_owned()), + gacha: Some(gacha), ..self } } @@ -85,7 +85,7 @@ impl BannerBuilder { /// let banner_builder = BannerBuilder::new("ピックアップ募集") /// .with_sparkable_students(&students); /// ``` - pub fn with_sparkable_students(self, students: &[Student]) -> Self { + pub fn with_sparkable_students(self, students: Vec) -> Self { Self { sparkable: Some(students.to_vec()), ..self diff --git a/src/gacha.rs b/src/gacha.rs index 6b0c593..3aa620f 100644 --- a/src/gacha.rs +++ b/src/gacha.rs @@ -1,6 +1,11 @@ use crate::student::{PriorityStudent, Student}; use serde_repr::{Deserialize_repr, Serialize_repr}; use std::cmp::Ordering; + +const THREE_STAR_RATE: usize = 25; +const TWO_STAR_RATE: usize = 185; +const ONE_STAR_RATE: usize = 790; + #[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq, Eq)] #[repr(u8)] /// The Available Rarities in Blue Archive's Gacha System @@ -72,7 +77,7 @@ pub struct GachaBuilder { impl Default for GachaBuilder { fn default() -> Self { Self { - rates: Some((790, 185, 25)), + rates: Some((ONE_STAR_RATE, TWO_STAR_RATE, THREE_STAR_RATE)), pool: Default::default(), priority: Default::default(), } @@ -146,9 +151,9 @@ impl GachaBuilder { /// .with_pool(pool) /// .with_priority(&priority); /// ``` - pub fn with_priority(self, students: &[PriorityStudent]) -> Self { + pub fn with_priority(self, students: Vec) -> Self { Self { - priority: Some(students.to_vec()), + priority: Some(students), ..self } }