Added the ability to get tags from the database.

Also fixed the way the example was compiling so it didn't act weird on
other features.
This commit is contained in:
2025-09-07 17:46:18 -04:00
parent 6bf4aa4bdb
commit 80e0fba845
3 changed files with 41 additions and 4 deletions

View File

@ -1,13 +1,16 @@
#![cfg(feature = "publisher")]
#[cfg(feature = "publisher")]
use chrono::NaiveDate;
#[cfg(feature = "publisher")]
use tavern::{Adventurer, Legend, Lore, Story, Tale, Tavern};
#[cfg(feature = "publisher")]
use tavern::Database;
/// This will generate a tavern that we can create a Toml file from.
#[cfg(feature = "publisher")]
fn generate_tavern() -> Tavern
{
let legend: Legend = Legend
@ -73,6 +76,7 @@ fn generate_tavern() -> Tavern
}
#[cfg(feature = "publisher")]
fn create_temp_file<P>(filename: P) -> std::path::PathBuf
where P: AsRef<std::path::Path>
{
@ -82,6 +86,7 @@ fn create_temp_file<P>(filename: P) -> std::path::PathBuf
path
}
#[cfg(feature = "publisher")]
fn cleanup_temp_file<P>(path: P)
where P: AsRef<std::path::Path>
{
@ -102,6 +107,7 @@ fn cleanup_temp_file<P>(path: P)
}
}
#[cfg(feature = "publisher")]
fn write_to_file<P>(tavern: Tavern, config_file: P) -> Result<(), Box<dyn std::error::Error>>
where P: AsRef<std::path::Path>
{
@ -112,6 +118,7 @@ fn write_to_file<P>(tavern: Tavern, config_file: P) -> Result<(), Box<dyn std::e
Ok(())
}
#[cfg(feature = "publisher")]
fn read_from_file<P>(config_file: P) -> Tavern
where P: AsRef<std::path::Path>
{
@ -124,6 +131,7 @@ fn read_from_file<P>(config_file: P) -> Tavern
}
#[cfg(feature = "publisher")]
async fn create_database() -> Result<(), Box<dyn std::error::Error>>
{
// First we need to generate a TOML file to work with.
@ -148,6 +156,7 @@ async fn create_database() -> Result<(), Box<dyn std::error::Error>>
Ok(())
}
#[cfg(feature = "publisher")]
#[tokio::main]
pub async fn main()
{
@ -157,3 +166,10 @@ pub async fn main()
Err(e) => { eprintln!("Error: {}", e); }
}
}
#[cfg(not(feature = "publisher"))]
#[tokio::main]
pub async fn main()
{
}