fix: improve type signatures of some methods

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-04-14 02:12:18 -05:00
parent 3c47ec8d4f
commit d5df9d4d30
3 changed files with 14 additions and 9 deletions

View File

@ -37,15 +37,15 @@ fn main() {
let gacha = GachaBuilder::new(ONE_STAR_RATE, TWO_STAR_RATE, THREE_STAR_RATE) let gacha = GachaBuilder::new(ONE_STAR_RATE, TWO_STAR_RATE, THREE_STAR_RATE)
.with_pool(students) .with_pool(students)
.with_priority(&priority) .with_priority(priority)
.finish() .finish()
.unwrap(); .unwrap();
// I'm some N5 loser don't judge too hard pls... // I'm some N5 loser don't judge too hard pls...
let banner = BannerBuilder::new("不運ですね。") let banner = BannerBuilder::new("不運ですね。")
.with_name_translation(Language::English, "Unlucky, right?") .with_name_translation(Language::English, "Unlucky, right?")
.with_sparkable_students(&sparkable) .with_sparkable_students(sparkable)
.with_gacha(&gacha) .with_gacha(gacha)
.finish() .finish()
.unwrap(); .unwrap();

View File

@ -65,9 +65,9 @@ impl BannerBuilder {
/// let banner_builder = BannerBuilder::new("ピックアップ募集") /// let banner_builder = BannerBuilder::new("ピックアップ募集")
/// .with_gacha(&gacha); /// .with_gacha(&gacha);
/// ``` /// ```
pub fn with_gacha(self, gacha: &Gacha) -> Self { pub fn with_gacha(self, gacha: Gacha) -> Self {
Self { Self {
gacha: Some(gacha.to_owned()), gacha: Some(gacha),
..self ..self
} }
} }
@ -85,7 +85,7 @@ impl BannerBuilder {
/// let banner_builder = BannerBuilder::new("ピックアップ募集") /// let banner_builder = BannerBuilder::new("ピックアップ募集")
/// .with_sparkable_students(&students); /// .with_sparkable_students(&students);
/// ``` /// ```
pub fn with_sparkable_students(self, students: &[Student]) -> Self { pub fn with_sparkable_students(self, students: Vec<Student>) -> Self {
Self { Self {
sparkable: Some(students.to_vec()), sparkable: Some(students.to_vec()),
..self ..self

View File

@ -1,6 +1,11 @@
use crate::student::{PriorityStudent, Student}; use crate::student::{PriorityStudent, Student};
use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_repr::{Deserialize_repr, Serialize_repr};
use std::cmp::Ordering; 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)] #[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
/// The Available Rarities in Blue Archive's Gacha System /// The Available Rarities in Blue Archive's Gacha System
@ -72,7 +77,7 @@ pub struct GachaBuilder {
impl Default for GachaBuilder { impl Default for GachaBuilder {
fn default() -> Self { fn default() -> Self {
Self { Self {
rates: Some((790, 185, 25)), rates: Some((ONE_STAR_RATE, TWO_STAR_RATE, THREE_STAR_RATE)),
pool: Default::default(), pool: Default::default(),
priority: Default::default(), priority: Default::default(),
} }
@ -146,9 +151,9 @@ impl GachaBuilder {
/// .with_pool(pool) /// .with_pool(pool)
/// .with_priority(&priority); /// .with_priority(&priority);
/// ``` /// ```
pub fn with_priority(self, students: &[PriorityStudent]) -> Self { pub fn with_priority(self, students: Vec<PriorityStudent>) -> Self {
Self { Self {
priority: Some(students.to_vec()), priority: Some(students),
..self ..self
} }
} }