|
| 1 | +// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> |
| 2 | +// SPDX-FileContributor: Andrew Hayzen <[email protected]> |
| 3 | +// |
| 4 | +// SPDX-License-Identifier: MIT OR Apache-2.0 |
| 5 | + |
| 6 | +use cxx::{type_id, ExternType}; |
| 7 | +use std::mem::MaybeUninit; |
| 8 | + |
| 9 | +#[cxx::bridge] |
| 10 | +mod ffi { |
| 11 | + unsafe extern "C++" { |
| 12 | + include!("cxx-qt-lib/qtypes.h"); |
| 13 | + |
| 14 | + #[cxx_name = "qint64"] |
| 15 | + type QInt64 = super::QInt64; |
| 16 | + |
| 17 | + #[cxx_name = "qsizetype"] |
| 18 | + type QSizeType = super::QSizeType; |
| 19 | + } |
| 20 | + |
| 21 | + #[namespace = "rust::cxxqtlib1"] |
| 22 | + unsafe extern "C++" { |
| 23 | + #[rust_name = "qint64_from_i64"] |
| 24 | + fn qint64FromI64(value: i64) -> QInt64; |
| 25 | + #[rust_name = "qint64_into_i64"] |
| 26 | + fn qint64IntoI64(value: QInt64) -> i64; |
| 27 | + |
| 28 | + #[rust_name = "qsizetype_from_isize"] |
| 29 | + fn qsizetypeFromIsize(value: isize) -> QSizeType; |
| 30 | + #[rust_name = "qsizetype_into_isize"] |
| 31 | + fn qsizetypeIntoIsize(value: QSizeType) -> isize; |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +#[repr(C)] |
| 36 | +pub struct QInt64 { |
| 37 | + _space: MaybeUninit<i64>, |
| 38 | +} |
| 39 | + |
| 40 | +impl From<i64> for QInt64 { |
| 41 | + fn from(value: i64) -> Self { |
| 42 | + ffi::qint64_from_i64(value) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +impl From<QInt64> for i64 { |
| 47 | + fn from(value: QInt64) -> Self { |
| 48 | + ffi::qint64_into_i64(value) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +// Safety: |
| 53 | +// |
| 54 | +// Static checks on the C++ side to ensure the size is the same. |
| 55 | +unsafe impl ExternType for QInt64 { |
| 56 | + type Id = type_id!("qint64"); |
| 57 | + type Kind = cxx::kind::Trivial; |
| 58 | +} |
| 59 | + |
| 60 | +#[repr(C)] |
| 61 | +pub struct QSizeType { |
| 62 | + _space: MaybeUninit<isize>, |
| 63 | +} |
| 64 | + |
| 65 | +impl From<isize> for QSizeType { |
| 66 | + fn from(value: isize) -> Self { |
| 67 | + ffi::qsizetype_from_isize(value) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +impl From<QSizeType> for isize { |
| 72 | + fn from(value: QSizeType) -> Self { |
| 73 | + ffi::qsizetype_into_isize(value) |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +// Safety: |
| 78 | +// |
| 79 | +// Static checks on the C++ side to ensure the size is the same. |
| 80 | +unsafe impl ExternType for QSizeType { |
| 81 | + type Id = type_id!("qsizetype"); |
| 82 | + type Kind = cxx::kind::Trivial; |
| 83 | +} |
0 commit comments