diff --git a/whatsrust/src/actions.rs b/whatsrust/src/actions.rs index 5f9d2e3..15961e1 100644 --- a/whatsrust/src/actions.rs +++ b/whatsrust/src/actions.rs @@ -1,3 +1,5 @@ +use std::ffi::CString; + use super::*; pub(crate) fn reaction_to_ffi( diff --git a/whatsrust/src/lib.rs b/whatsrust/src/lib.rs index 339438b..a0a35b4 100644 --- a/whatsrust/src/lib.rs +++ b/whatsrust/src/lib.rs @@ -2,8 +2,6 @@ //! Implementation and focused tests live in owning modules. //! Explicit reexports keep the public API boundary auditable. -use std::ffi::CString; - #[macro_use] mod callbacks; mod abi; @@ -37,7 +35,7 @@ pub use models::{ FileId, FileKind, ForwardingInfo, GroupInfo, GroupInfoError, GroupParticipant, JID, LogoutError, Mention, Message, MessageActionFailed, MessageActionKind, MessageContent, MessageId, MessageInfo, PresenceUpdate, ProfilePicture, ProfilePictureAvailability, - ProfilePictureError, + ProfilePictureError, VIEW_ONCE_UNAVAILABLE_DESCRIPTION, }; pub use presence::{SubscribePresenceResult, drain_raw_presence_diagnostics, subscribe_presence}; pub use queries::{ @@ -54,18 +52,3 @@ pub use caches::{ remove_forward_source, store_forward_source, store_message_mention_ranges, store_message_push_name, }; - -pub const VIEW_ONCE_UNAVAILABLE_DESCRIPTION: &str = - "View-once media is unavailable here. View it on your phone."; - -impl CallbackTranslator for JID { - unsafe fn to_rust(from: CJID) -> Self { - (&from).into() - } -} - -impl CallbackTranslator for i64 { - unsafe fn to_rust(value: i64) -> Self { - value - } -} diff --git a/whatsrust/src/lifecycle.rs b/whatsrust/src/lifecycle.rs index 1c1fb85..3ab9d75 100644 --- a/whatsrust/src/lifecycle.rs +++ b/whatsrust/src/lifecycle.rs @@ -1,4 +1,4 @@ -use std::ffi::{CStr, c_char}; +use std::ffi::{CStr, CString, c_char}; use super::*; diff --git a/whatsrust/src/media.rs b/whatsrust/src/media.rs index ff23386..82e3925 100644 --- a/whatsrust/src/media.rs +++ b/whatsrust/src/media.rs @@ -1,4 +1,7 @@ -use std::{ffi::CStr, path::Path}; +use std::{ + ffi::{CStr, CString}, + path::Path, +}; use super::*; diff --git a/whatsrust/src/models.rs b/whatsrust/src/models.rs index fdc537b..a5f50ff 100644 --- a/whatsrust/src/models.rs +++ b/whatsrust/src/models.rs @@ -6,6 +6,7 @@ use std::{ use strum::{EnumIter, FromRepr}; use crate::abi::{CContact, CJID, LogoutStatus, ReceiptKind}; +use crate::callbacks::CallbackTranslator; #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct JID(pub Arc); @@ -34,6 +35,15 @@ impl From<&JID> for CJID { } } +impl CallbackTranslator for JID { + unsafe fn to_rust(from: CJID) -> Self { + (&from).into() + } +} + +pub const VIEW_ONCE_UNAVAILABLE_DESCRIPTION: &str = + "View-once media is unavailable here. View it on your phone."; + pub type MessageId = Arc; #[derive(Clone, Debug)] diff --git a/whatsrust/src/presence.rs b/whatsrust/src/presence.rs index 9c6d741..5fe807a 100644 --- a/whatsrust/src/presence.rs +++ b/whatsrust/src/presence.rs @@ -1,5 +1,5 @@ use std::{ - ffi::{CStr, c_char}, + ffi::{CStr, CString, c_char}, sync::atomic::{AtomicUsize, Ordering}, }; diff --git a/whatsrust/src/registrations.rs b/whatsrust/src/registrations.rs index 72680cd..074b35a 100644 --- a/whatsrust/src/registrations.rs +++ b/whatsrust/src/registrations.rs @@ -20,6 +20,12 @@ impl CallbackTranslator for u8 { } } +impl CallbackTranslator for i64 { + unsafe fn to_rust(value: i64) -> Self { + value + } +} + pub fn set_presence_handler(mut callback: F) where F: FnMut(PresenceUpdate) + 'static,