summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbogdasar1985 <bogdasar1985@gmail.com>2023-11-01 14:24:11 +0500
committerAlexander Batischev <eual.jp@gmail.com>2024-10-01 19:12:43 +0300
commite35da9dea747069efd8786727a5bdc75594c6972 (patch)
tree9cd2e94e165c49b545e57d7bd88d2d39569f33a9
parentc255ef66dc1f503b0808ee6562b01379643448de (diff)
Change History::load_from_file() to accept PathBuf
-rw-r--r--rust/libnewsboat-ffi/src/history.rs14
-rw-r--r--src/history.cpp2
2 files changed, 12 insertions, 4 deletions
diff --git a/rust/libnewsboat-ffi/src/history.rs b/rust/libnewsboat-ffi/src/history.rs
index 922c680b..26b777c3 100644
--- a/rust/libnewsboat-ffi/src/history.rs
+++ b/rust/libnewsboat-ffi/src/history.rs
@@ -1,3 +1,4 @@
+use crate::filepath::PathBuf;
use libnewsboat::history;
// cxx doesn't allow to share types from other crates, so we have to wrap it
@@ -6,6 +7,13 @@ struct History(history::History);
#[cxx::bridge(namespace = "newsboat::history::bridged")]
mod bridged {
+ #[namespace = "newsboat::filepath::bridged"]
+ extern "C++" {
+ include!("libnewsboat-ffi/src/filepath.rs.h");
+
+ type PathBuf = crate::filepath::PathBuf;
+ }
+
extern "Rust" {
type History;
@@ -14,7 +22,7 @@ mod bridged {
fn add_line(history: &mut History, line: &str);
fn previous_line(history: &mut History) -> String;
fn next_line(history: &mut History) -> String;
- fn load_from_file(history: &mut History, file: &str);
+ fn load_from_file(history: &mut History, file: &PathBuf);
fn save_to_file(history: &mut History, file: &str, limit: usize);
}
}
@@ -35,10 +43,10 @@ fn next_line(history: &mut History) -> String {
history.0.next_line()
}
-fn load_from_file(history: &mut History, file: &str) {
+fn load_from_file(history: &mut History, file: &PathBuf) {
// Original C++ code did nothing if it failed to open file.
// Returns a [must_use] type so safely ignoring the value.
- let _ = history.0.load_from_file(file);
+ let _ = history.0.load_from_file(&file.0);
}
fn save_to_file(history: &mut History, file: &str, limit: usize) {
diff --git a/src/history.cpp b/src/history.cpp
index 8ea86a20..3c60d3c5 100644
--- a/src/history.cpp
+++ b/src/history.cpp
@@ -24,7 +24,7 @@ std::string History::next_line()
void History::load_from_file(const Filepath& file)
{
- history::bridged::load_from_file(*rs_object, file.to_locale_string());
+ history::bridged::load_from_file(*rs_object, file);
}
void History::save_to_file(const Filepath& file, unsigned int limit)