Skip to content

Commit dc56c9d

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 dc56c9d

29 files changed

+96
-100
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ 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
27-
#[derive(QObject,Default)]
25+
#[derive(QObject, Default)]
2826
struct Greeter {
2927
// Specify the base class with the qt_base_class macro
3028
base: qt_base_class!(trait QObject),

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/graph/src/nodes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use cpp::cpp;
22

33
use qmetaobject::scenegraph::SGNode;
4-
use qmetaobject::{qrc, QColor, QQuickItem, QRectF};
4+
use qmetaobject::{qrc, QQuickItem};
5+
use qttypes::{QColor, QRectF};
56

67
qrc! {
78
init_resource,

examples/qmlextensionplugins/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ name = "qmlqtimeexampleplugin"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
qmetaobject = { path = "../../qmetaobject"}
12+
qmetaobject = { path = "../../qmetaobject" }
1313
chrono = "^0.4"
14+
cstr = "0.2"

examples/qmlextensionplugins/src/lib.rs

Lines changed: 9 additions & 12 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) {
79-
//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-
);
80+
fn register_types(&mut self, uri: &CStr) {
81+
//assert_eq!(uri, cstr!("TimeExample"));
82+
qml_register_type::<TimeModel>(uri, 1, 0, cstr!("Time"));
8683
}
8784
}

examples/todos/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ edition = "2018"
55
authors = ["Olivier Goffart <ogoffart@woboq.com>"]
66

77
[dependencies]
8-
qmetaobject = { path = "../../qmetaobject"}
8+
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)> {

0 commit comments

Comments
 (0)