Fetching modules and their names

This commit is contained in:
Greg Hellings
2025-02-24 22:35:47 -06:00
parent 3e2cd701d0
commit 87fde0db10
3 changed files with 39 additions and 2 deletions
+5
View File
@@ -3,13 +3,18 @@
#include <memory>
#include <string>
#include <sword/swmgr.h>
#include "rust/cxx.h"
#include "module.h"
class Mgr : public sword::SWMgr {
public:
Mgr();
Mgr(const char*);
rust::Vec<rust::String> get_modules() const;
std::unique_ptr<Module> get_module(const rust::String &name) {
return std::unique_ptr<Module>(new Module(this->getModule(std::string(name).c_str())));
};
};
std::unique_ptr<Mgr> new_mgr();
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#include <sword/swmodule.h>
#include <string>
#include "rust/cxx.h"
class Module {
private:
sword::SWModule* module;
public:
Module(sword::SWModule* module) : module(module) { };
rust::String get_name() const {
return rust::String(this->module->getName());
}
rust::String strip_text() {
return std::string(
(const char*) this->module->stripText()
);
}
};
+11 -2
View File
@@ -4,12 +4,18 @@ pub use ffi::*;
mod ffi {
unsafe extern "C++" {
include!("sword_rs/src/cxx/mgr.h");
include!("sword_rs/src/cxx/module.h");
type Mgr;
type Module;
fn new_mgr() -> UniquePtr<Mgr>;
fn new_mgr_with_path(path: &String) -> UniquePtr<Mgr>;
fn get_modules(&self) -> Vec<String>;
fn get_modules(self: &Mgr) -> Vec<String>;
fn get_module(self: Pin<&mut Mgr>, name: &String) -> UniquePtr<Module>;
fn get_name(self: &Module) -> String;
fn strip_text(self: Pin<&mut Module>) -> String;
}
}
@@ -43,9 +49,12 @@ mod tests {
writeln!(file, "Description=Test description").unwrap();
writeln!(file, "About=A test conf file").unwrap();
}
let mgr = ffi::new_mgr_with_path(&dir.path().to_str().unwrap().to_string());
let mut mgr = ffi::new_mgr_with_path(&dir.path().to_str().unwrap().to_string());
assert!(mgr.get_modules().len() == 1);
assert!(mgr.get_modules().contains(&String::from("KJVdummy")));
let mut module = mgr.pin_mut().get_module(&String::from("KJVdummy"));
assert!(module.pin_mut().get_name() == "KJVdummy");
}
#[test]