adds docs, removes some useless pub statements

This commit is contained in:
2019-10-19 16:12:27 +02:00
parent a552d7beee
commit 24807615f7
5 changed files with 47 additions and 16 deletions

View File

@@ -13,14 +13,16 @@ type OwnedBy = Select<OwnedLoot, ItemColumns>;
pub struct Item {
pub id: i32,
pub name: String,
pub base_price: i32,
base_price: i32,
}
impl Item {
/// Returns this item value
pub fn value(&self) -> i32 {
self.base_price
}
/// Returns this item sell value
pub fn sell_value(&self) -> i32 {
self.base_price / 2
}
@@ -33,10 +35,12 @@ impl Item {
pub struct Inventory<'q>(pub &'q DbConnection);
impl<'q> Inventory<'q> {
/// Get all items from Inventory
pub fn all(&self) -> QueryResult<Vec<Item>> {
items::table.load::<Item>(self.0)
}
/// Find an item in Inventory
pub fn find(&self, item_id: i32) -> QueryResult<Item> {
items::table.find(item_id).first::<Item>(self.0)
}
@@ -86,7 +90,7 @@ impl Loot {
}
}
/// Manager for a player's loot
/// Manager for a *single* player loot
pub struct LootManager<'q>(pub &'q DbConnection, pub i32);
impl<'q> LootManager<'q> {
@@ -96,6 +100,9 @@ impl<'q> LootManager<'q> {
}
/// Finds an item by id
///
/// Returns a NotFound error if an item is found by it
/// does not belong to this player
pub fn find(&self, loot_id: i32) -> QueryResult<Item> {
Ok(Loot::find(loot_id).first(self.0).and_then(|loot: Loot| {
if loot.owner != self.1 {