From 56518420bced2472e18fc093b1a6816c19ce6a1b Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Mon, 29 Jun 2020 06:21:52 +0300 Subject: [PATCH] Add get_marker method to dc_array_t --- deltachat-ffi/src/dc_array.rs | 11 +++++++++++ deltachat-ffi/src/lib.rs | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/deltachat-ffi/src/dc_array.rs b/deltachat-ffi/src/dc_array.rs index 36ee3fc0f..7c5d87a5e 100644 --- a/deltachat-ffi/src/dc_array.rs +++ b/deltachat-ffi/src/dc_array.rs @@ -39,6 +39,17 @@ impl dc_array_t { } } + pub(crate) fn get_marker(&self, index: usize) -> Option<&str> { + match self { + Self::MsgIds(_) => None, + Self::Chat(array) => None, + Self::Locations(array) => array + .get(index) + .and_then(|location| location.marker.as_deref()), + Self::Uint(_) => None, + } + } + pub(crate) fn get_location(&self, index: usize) -> &Location { if let Self::Locations(array) = self { &array[index] diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 7d9156dbc..c09fafb54 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -2068,7 +2068,7 @@ pub unsafe extern "C" fn dc_array_get_marker( return std::ptr::null_mut(); // NULL explicitly defined as "no markers" } - if let Some(s) = &(*array).get_location(index).marker { + if let Some(s) = (*array).get_marker(index) { s.strdup() } else { std::ptr::null_mut()