Add the ability to read type
This commit is contained in:
@@ -16,6 +16,7 @@ pub mod ffi {
|
||||
|
||||
fn decrement(self: Pin<&mut Module>);
|
||||
fn get_name(self: &Module) -> String;
|
||||
fn get_type(self: &Module) -> String;
|
||||
fn increment(self: Pin<&mut Module>);
|
||||
fn is_skip_consecutive_links(self: &Module) -> bool;
|
||||
fn render_text(self: Pin<&mut Module>) -> String;
|
||||
|
||||
@@ -11,6 +11,10 @@ namespace sword_rs {
|
||||
return rust::String(this->module->getName());
|
||||
}
|
||||
|
||||
rust::String Module::get_type() const {
|
||||
return rust::String(this->module->getType());
|
||||
}
|
||||
|
||||
void Module::increment() {
|
||||
this->module->increment();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace sword_rs {
|
||||
|
||||
rust::String get_name() const;
|
||||
|
||||
rust::String get_type() const;
|
||||
|
||||
void increment();
|
||||
|
||||
bool is_skip_consecutive_links() const;
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
mod cxx;
|
||||
pub mod mgr;
|
||||
mod module;
|
||||
pub mod module;
|
||||
|
||||
+21
-12
@@ -5,18 +5,27 @@ fn main() {
|
||||
let mut mgr = Mgr::new_with_format(Format::HTMLHref);
|
||||
for mod_name in mgr.get_modules() {
|
||||
let mut module = mgr.get_module(&mod_name);
|
||||
println!("Module: {}", module.get_name());
|
||||
let random_number: i32 = rand::rng().random_range(1..=20);
|
||||
let random_number_str = format!("John.3.{}", random_number);
|
||||
module.set_key_text(&random_number_str);
|
||||
module.set_skip_consecutive_links(true);
|
||||
for i in 0..10 {
|
||||
module.increment();
|
||||
println!(
|
||||
"Text John 3:{} is \"{}\"",
|
||||
random_number + i,
|
||||
module.render_text()
|
||||
);
|
||||
// module.get_type();
|
||||
println!(
|
||||
"Module: {} which is a {}",
|
||||
module.get_name(),
|
||||
module.get_type().get_name()
|
||||
);
|
||||
if module.get_type() == sword_rs::module::Type::BiblicalTexts {
|
||||
let random_number: i32 = rand::rng().random_range(1..=20);
|
||||
let random_number_str = format!("John.3.{}", random_number);
|
||||
module.set_key_text(&random_number_str);
|
||||
module.set_skip_consecutive_links(true);
|
||||
for i in 0..10 {
|
||||
println!(
|
||||
"Text John 3:{} is \"{}\"",
|
||||
random_number + i,
|
||||
module.render_text()
|
||||
);
|
||||
module.increment();
|
||||
}
|
||||
} else {
|
||||
println!("This is not a Bible");
|
||||
}
|
||||
println!("==============================");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,40 @@
|
||||
use crate::cxx::ffi;
|
||||
use cxx::UniquePtr;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum Type {
|
||||
Unknown,
|
||||
BiblicalTexts,
|
||||
Commentaries,
|
||||
DailyDevotional,
|
||||
GenericBooks,
|
||||
Lexicons,
|
||||
}
|
||||
|
||||
impl Type {
|
||||
pub fn new(type_str: &String) -> Self {
|
||||
match type_str.as_str() {
|
||||
"Biblical Texts" => Type::BiblicalTexts,
|
||||
"Commentaries" => Type::Commentaries,
|
||||
"Daily Devotional" => Type::DailyDevotional,
|
||||
"Generic Books" => Type::GenericBooks,
|
||||
"Lexicons / Dictionaries" => Type::Lexicons,
|
||||
_ => Type::Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> String {
|
||||
match self {
|
||||
Type::BiblicalTexts => String::from("Biblical Texts"),
|
||||
Type::Commentaries => String::from("Commentaries"),
|
||||
Type::DailyDevotional => String::from("Daily Devotional"),
|
||||
Type::GenericBooks => String::from("Generic Books"),
|
||||
Type::Lexicons => String::from("Lexicons / Dictionaries"),
|
||||
Type::Unknown => String::from("Unknown"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Module {
|
||||
module: UniquePtr<ffi::Module>,
|
||||
}
|
||||
@@ -18,6 +52,14 @@ impl Module {
|
||||
self.module.get_name()
|
||||
}
|
||||
|
||||
pub fn get_type(&self) -> Type {
|
||||
// This line I will use to see what the C++ library returns
|
||||
// for all module types.
|
||||
// You can also check swmgr.cpp for the list
|
||||
// println!("{}", self.module.get_type());
|
||||
Type::new(&self.module.get_type())
|
||||
}
|
||||
|
||||
pub fn increment(&mut self) {
|
||||
self.module.pin_mut().increment();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user