pub struct RemoteDatabase {
pub mods: HashMap<String, RemoteMod>,
pub owml: Option<RemoteMod>,
}
Expand description
Query the remote database of mods Represents the remote (on the website) database of mods.
Fields§
§mods: HashMap<String, RemoteMod>
A hashmap of unique names to mods
owml: Option<RemoteMod>
OWML, if it exists
Implementations§
Source§impl RemoteDatabase
impl RemoteDatabase
Sourcepub async fn fetch(url: &str) -> Result<RemoteDatabase>
pub async fn fetch(url: &str) -> Result<RemoteDatabase>
Fetch the database of remote mods.
§Returns
An object containing a hashmap of unique names to mods.
§Errors
If we can’t fetch the JSON file for whatever reason.
§Examples
use owmods_core::db::RemoteDatabase;
use owmods_core::config::Config;
let config = Config::get(None).unwrap();
let db = RemoteDatabase::fetch(&config.database_url).await.unwrap();
let time_saver = db.get_mod("Bwc9876.TimeSaver").unwrap();
assert_eq!(time_saver.unique_name, "Bwc9876.TimeSaver");
assert_eq!(time_saver.name, "Time Saver");
Sourcepub fn fetch_blocking(url: &str) -> Result<RemoteDatabase>
pub fn fetch_blocking(url: &str) -> Result<RemoteDatabase>
Fetch the database but block the current thread while doing so
§Returns
An object containing a hashmap of unique names to mods.
§Errors
If we can’t fetch the JSON file for whatever reason.
§Examples
use owmods_core::db::RemoteDatabase;
use owmods_core::config::Config;
let config = Config::get(None).unwrap();
let db = RemoteDatabase::fetch_blocking(&config.database_url).unwrap();
let time_saver = db.get_mod("Bwc9876.TimeSaver").unwrap();
assert_eq!(time_saver.unique_name, "Bwc9876.TimeSaver");
Sourcepub fn get_mod(&self, unique_name: &str) -> Option<&RemoteMod>
pub fn get_mod(&self, unique_name: &str) -> Option<&RemoteMod>
Get a mod by unique name, will not return OWML.
§Returns
A reference to the requested mod in the database, or None
if it doesn’t exist.
§Examples
use owmods_core::db::RemoteDatabase;
use owmods_core::config::Config;
use owmods_core::constants::OWML_UNIQUE_NAME;
let config = Config::get(None).unwrap();
let db = RemoteDatabase::fetch_blocking(&config.database_url).unwrap();
let time_saver = db.get_mod("Bwc9876.TimeSaver").unwrap();
let owml = db.get_mod(OWML_UNIQUE_NAME);
assert!(owml.is_none());
Sourcepub fn get_owml(&self) -> Option<&RemoteMod>
pub fn get_owml(&self) -> Option<&RemoteMod>
Gets OWML from the database
§Returns
A reference to OWML if it’s in the database
§Examples
use owmods_core::db::RemoteDatabase;
use owmods_core::config::Config;
use owmods_core::constants::OWML_UNIQUE_NAME;
let config = Config::get(None).unwrap();
let db = RemoteDatabase::fetch_blocking(&config.database_url).unwrap();
let owml = db.get_owml().unwrap();
assert_eq!(owml.unique_name, OWML_UNIQUE_NAME);
Sourcepub fn search(&self, search: &str) -> Vec<&RemoteMod>
pub fn search(&self, search: &str) -> Vec<&RemoteMod>
Search the database with the given query, pulls from various fields of the mod
§Returns
A Vec of RemoteMods that exactly or closely match the search query
§Examples
use owmods_core::db::RemoteDatabase;
use owmods_core::config::Config;
let config = Config::get(None).unwrap();
let db = RemoteDatabase::fetch_blocking(&config.database_url).unwrap();
let mods = db.search("time saver");
assert_eq!(mods.first().unwrap().unique_name, "Bwc9876.TimeSaver");
let mods = db.search("time");
assert_eq!(mods.first().unwrap().unique_name, "Bwc9876.TimeSaver");
let mods = db.search("saver");
assert_eq!(mods.first().unwrap().unique_name, "Bwc9876.TimeSaver");
let mods = db.search("Bwc9876");
assert_eq!(mods.first().unwrap().unique_name, "Bwc9876.TimeSaver");
let mods = db.search("A mod that skips various");
assert_eq!(mods.first().unwrap().unique_name, "Bwc9876.TimeSaver");
Get all the tags of all mods in the database, sorted by how often they appear
§Returns
A Vec<String>
of tags sorted by the amount of times they appear in the database (highest -> lowest)
§Examples
use owmods_core::db::RemoteDatabase;
use owmods_core::config::Config;
let config = Config::get(None).unwrap();
let db = RemoteDatabase::fetch_blocking(&config.database_url).unwrap();
let tags = db.get_tags();
assert_eq!(tags[0], "content");
Filter a list of mods by a list of tags
- Note this performs an OR on the tags, meaning if it matches one of them it passes (reflects website logic)
§Returns
An iterator over the mods that match the given list of tags
§Examples
use owmods_core::db::RemoteDatabase;
use owmods_core::config::Config;
let config = Config::get(None).unwrap();
let db = RemoteDatabase::fetch_blocking(&config.database_url).unwrap();
let mut mods = RemoteDatabase::filter_by_tags(db.mods.values(), vec!["tool".to_string(), "tweaks".to_string()]);
assert!(mods.any(|m| m.unique_name == "Bwc9876.TimeSaver"));
Get all mods in the db that match the given list of tags
- Note this performs an OR on the tags, meaning if it matches one of them it passes (reflects website logic)
§Returns
An iterator over the mods that match the given list of tags
§Examples
use owmods_core::db::RemoteDatabase;
use owmods_core::config::Config;
let config = Config::get(None).unwrap();
let db = RemoteDatabase::fetch_blocking(&config.database_url).unwrap();
let mut mods = db.matches_tags(vec!["tool".to_string(), "tweaks".to_string()]);
assert!(mods.any(|m| m.unique_name == "Bwc9876.TimeSaver"));
Trait Implementations§
Source§impl Clone for RemoteDatabase
impl Clone for RemoteDatabase
Source§fn clone(&self) -> RemoteDatabase
fn clone(&self) -> RemoteDatabase
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for RemoteDatabase
impl Debug for RemoteDatabase
Source§impl Default for RemoteDatabase
impl Default for RemoteDatabase
Source§fn default() -> RemoteDatabase
fn default() -> RemoteDatabase
Auto Trait Implementations§
impl Freeze for RemoteDatabase
impl RefUnwindSafe for RemoteDatabase
impl Send for RemoteDatabase
impl Sync for RemoteDatabase
impl Unpin for RemoteDatabase
impl UnwindSafe for RemoteDatabase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more