-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement basic casting for some lib types
- Loading branch information
1 parent
f6c1f8c
commit c60cdfe
Showing
4 changed files
with
84 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ | |
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
use crate::core::qstringlist::ffi::{downcast_qlist_qstring, upcast_qstringlist, QList_QString}; | ||
use crate::{QList, QString}; | ||
use core::mem::MaybeUninit; | ||
use cxx::{type_id, ExternType}; | ||
use cxx_qt::Upcast; | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
#[cxx::bridge] | ||
|
@@ -25,6 +27,20 @@ mod ffi { | |
include!("cxx-qt-lib/qstringlist.h"); | ||
type QStringList = super::QStringList; | ||
|
||
include!("cxx-qt/casting.h"); | ||
|
||
#[doc(hidden)] | ||
#[rust_name = "upcast_qstringlist"] | ||
#[cxx_name = "upcastPtr"] | ||
#[namespace = "rust::cxxqt1"] | ||
unsafe fn upcast(thiz: *const QStringList) -> *const QList_QString; | ||
|
||
#[doc(hidden)] | ||
#[rust_name = "downcast_qlist_qstring"] | ||
#[cxx_name = "downcastPtr"] | ||
#[namespace = "rust::cxxqt1"] | ||
unsafe fn downcast(base: *const QList_QString) -> *const QStringList; | ||
|
||
/// Returns true if the list contains the string str; otherwise returns false. | ||
fn contains(self: &QStringList, str: &QString, cs: CaseSensitivity) -> bool; | ||
|
||
|
@@ -80,11 +96,6 @@ mod ffi { | |
|
||
#[namespace = "rust::cxxqtlib1"] | ||
unsafe extern "C++" { | ||
#[doc(hidden)] | ||
#[rust_name = "qstringlist_as_qlist_qstring_ref"] | ||
fn qstringlistAsQListQStringRef(list: &QStringList) -> &QList_QString; | ||
#[rust_name = "qstringlist_as_qlist_qstring_ref_mut"] | ||
fn qstringlistAsQListQStringRef(list: &mut QStringList) -> &mut QList_QString; | ||
#[doc(hidden)] | ||
#[rust_name = "qstringlist_from_qlist_qstring"] | ||
fn qstringlistFromQListQString(list: &QList_QString) -> QStringList; | ||
|
@@ -184,13 +195,23 @@ impl Deref for QStringList { | |
type Target = QList<QString>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
ffi::qstringlist_as_qlist_qstring_ref(self) | ||
self.upcast() | ||
} | ||
} | ||
|
||
impl DerefMut for QStringList { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
ffi::qstringlist_as_qlist_qstring_ref_mut(self) | ||
self.upcast_mut() | ||
} | ||
} | ||
|
||
impl Upcast<QList_QString> for QStringList { | ||
unsafe fn upcast_ptr(this: *const Self) -> *const QList_QString { | ||
upcast_qstringlist(this) | ||
} | ||
|
||
unsafe fn from_base_ptr(base: *const QList_QString) -> *const Self { | ||
downcast_qlist_qstring(base) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters