split decks into module

This commit is contained in:
Damien Elmes 2020-04-26 14:47:58 +10:00
parent bb56e9bc20
commit d3b27c302c
2 changed files with 28 additions and 21 deletions

27
rslib/src/decks/mod.rs Normal file
View file

@ -0,0 +1,27 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use crate::define_newtype;
mod schema11;
pub use schema11::Deck;
define_newtype!(DeckID, i64);
pub(crate) fn child_ids<'a>(decks: &'a [Deck], name: &str) -> impl Iterator<Item = DeckID> + 'a {
let prefix = format!("{}::", name.to_ascii_lowercase());
decks
.iter()
.filter(move |d| d.name().to_ascii_lowercase().starts_with(&prefix))
.map(|d| d.id())
}
pub(crate) fn get_deck(decks: &[Deck], id: DeckID) -> Option<&Deck> {
for d in decks {
if d.id() == id {
return Some(d);
}
}
None
}

View file

@ -1,8 +1,8 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use super::DeckID;
use crate::{
define_newtype,
serde::{default_on_invalid, deserialize_bool_from_anything, deserialize_number_from_string},
timestamp::TimestampSecs,
types::Usn,
@ -12,8 +12,6 @@ use serde_json::Value;
use serde_tuple::Serialize_tuple;
use std::collections::HashMap;
define_newtype!(DeckID, i64);
#[derive(Serialize, PartialEq, Debug, Clone)]
#[serde(untagged)]
pub enum Deck {
@ -218,21 +216,3 @@ impl Default for NormalDeck {
}
}
}
pub(crate) fn child_ids<'a>(decks: &'a [Deck], name: &str) -> impl Iterator<Item = DeckID> + 'a {
let prefix = format!("{}::", name.to_ascii_lowercase());
decks
.iter()
.filter(move |d| d.name().to_ascii_lowercase().starts_with(&prefix))
.map(|d| d.id())
}
pub(crate) fn get_deck(decks: &[Deck], id: DeckID) -> Option<&Deck> {
for d in decks {
if d.id() == id {
return Some(d);
}
}
None
}