Skip to content

Commit 4c1e8a8

Browse files
committed
transition paths to 2018 edition
Replaces all `extern crate ...` and especially #[macro_use] statements with direct `use`s of relevant items. Introduces cstr! crate & macro to examples, because we don't want our dear users/readers to suffer with raw CStr nightmare: std::ffi::CStr::from_bytes_with_nul(b"...\0").unwrap()
1 parent a2ae6c5 commit 4c1e8a8

File tree

28 files changed

+69
-69
lines changed

28 files changed

+69
-69
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ Presentation Blog Post: https://woboq.com/blog/qmetaobject-from-rust.html
1818
## Overview
1919

2020
```rust
21-
#[macro_use] extern crate cstr;
22-
extern crate qmetaobject;
23-
21+
use cstr::cstr;
2422
use qmetaobject::*;
2523

2624
// The `QObject` custom derive macro allows to expose a class to Qt and QML

examples/graph/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FO
1515
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1616
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717
*/
18-
extern crate cpp_build;
1918

2019
fn main() {
2120
let qt_include_path = std::env::var("DEP_QT_INCLUDE_PATH").unwrap();

examples/qmlextensionplugins/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ crate-type = ["cdylib"]
1111
[dependencies]
1212
qmetaobject = { path = "../../qmetaobject"}
1313
chrono = "^0.4"
14+
cstr = "0.2"

examples/qmlextensionplugins/src/lib.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
extern crate qmetaobject;
2-
use qmetaobject::*;
3-
extern crate chrono;
4-
use chrono::Timelike;
1+
use std::ffi::CStr;
52
use std::sync::{Arc, Condvar, Mutex};
63
use std::thread::JoinHandle;
74

5+
use chrono::Timelike;
6+
use cstr::cstr;
7+
8+
use qmetaobject::*;
9+
810
#[derive(Default)]
911
struct AbortCondVar {
1012
is_aborted: Mutex<bool>,
@@ -75,13 +77,8 @@ struct QExampleQmlPlugin {
7577
}
7678

7779
impl QQmlExtensionPlugin for QExampleQmlPlugin {
78-
fn register_types(&mut self, uri: &std::ffi::CStr) {
80+
fn register_types(&mut self, uri: &CStr) {
7981
//assert_eq!(uri, std::ffi::CStr::from_bytes_with_nul(b"TimeExample\0"));
80-
qml_register_type::<TimeModel>(
81-
uri,
82-
1,
83-
0,
84-
std::ffi::CStr::from_bytes_with_nul(b"Time\0").unwrap(),
85-
);
82+
qml_register_type::<TimeModel>(uri, 1, 0, cstr!("Time"));
8683
}
8784
}

examples/todos/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ authors = ["Olivier Goffart <ogoffart@woboq.com>"]
66

77
[dependencies]
88
qmetaobject = { path = "../../qmetaobject"}
9+
cstr = "0.2"

examples/todos/src/implementation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
* You should have received a copy of the GNU General Public License
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
21-
use qmetaobject::*;
2221
use std::collections::HashMap;
2322

23+
use qmetaobject::*;
24+
2425
#[derive(Default, Clone)]
2526
struct TodosItem {
2627
completed: bool,

examples/todos/src/main.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
extern crate qmetaobject;
2-
use qmetaobject::*;
1+
use cstr::cstr;
32

4-
use std::ffi::CStr;
3+
use qmetaobject::*;
54

65
mod implementation;
76

@@ -13,12 +12,7 @@ qrc!(my_resource,
1312

1413
fn main() {
1514
my_resource();
16-
qml_register_type::<implementation::Todos>(
17-
CStr::from_bytes_with_nul(b"RustCode\0").unwrap(),
18-
1,
19-
0,
20-
CStr::from_bytes_with_nul(b"Todos\0").unwrap(),
21-
);
15+
qml_register_type::<implementation::Todos>(cstr!("RustCode"), 1, 0, cstr!("Todos"));
2216
let mut engine = QmlEngine::new();
2317
engine.load_file("qrc:/todos/qml/main.qml".into());
2418
engine.exec();

examples/webengine/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate qmetaobject;
21
use qmetaobject::*;
32

43
qrc!(my_resource,

qmetaobject/src/connections.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8484
#![deny(missing_docs)]
8585
use std::os::raw::c_void;
8686

87+
use cpp::{cpp, cpp_class};
88+
8789
use super::*;
8890

8991
/// Inner functor type of a `QRustClosureSlotObject` class.
@@ -282,7 +284,7 @@ impl<Args> Signal<Args> {
282284
/// # Example
283285
///
284286
/// ```
285-
/// #[macro_use] extern crate cpp;
287+
/// use cpp::cpp;
286288
/// use qmetaobject::*;
287289
///
288290
/// fn object_name_changed() -> Signal<fn(QString)> {

qmetaobject/src/future.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::os::raw::c_void;
44
use std::pin::Pin;
55
use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
66

7+
use cpp::cpp;
8+
79
use crate::connections::SignalArgArrayToTuple;
810

911
static QT_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(

0 commit comments

Comments
 (0)