Skip to content

Commit 0624965

Browse files
committed
shorten paths: factor out extra double-colons to imports
* Most noticeably, shortened std::ffi::CStr[ing] and ::std::os::raw::c_void. * (qmetaobject/src/scenegraph.rs): - Removed probably misplaced #[cfg(qt_5.8)] attribute before use super::*; - Fixed indentation in screnegraph, because cargo fmt could be wrong when it comes to macros.
1 parent ad28e6c commit 0624965

File tree

10 files changed

+119
-108
lines changed

10 files changed

+119
-108
lines changed

examples/graph/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#![allow(non_snake_case)]
22
#![allow(unused_variables)]
3-
#[macro_use]
4-
extern crate qmetaobject;
5-
use qmetaobject::scenegraph::*;
6-
use qmetaobject::*;
3+
74
#[macro_use]
85
extern crate cstr;
96
#[macro_use]
107
extern crate cpp;
118

9+
use qmetaobject::scenegraph::*;
10+
use qmetaobject::*;
11+
1212
mod nodes;
1313

1414
#[derive(Default, QObject)]

examples/graph/src/nodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use qmetaobject::scenegraph::SGNode;
2-
use qmetaobject::{QColor, QQuickItem, QRectF};
2+
use qmetaobject::{qrc, QColor, QQuickItem, QRectF};
33

44
qrc! {
55
init_resource,

qmetaobject/src/connections.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,9 @@ impl<Args> Signal<Args> {
282282
/// # Example
283283
///
284284
/// ```
285-
/// # #[macro_use] extern crate cpp;
286-
/// # use qmetaobject::*;
285+
/// #[macro_use] extern crate cpp;
286+
/// use qmetaobject::*;
287+
///
287288
/// fn object_name_changed() -> Signal<fn(QString)> {
288289
/// unsafe {
289290
/// Signal::new(cpp!([] -> SignalInner as "SignalInner" {

qmetaobject/src/future.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::future::Future;
2+
use std::mem::replace;
23
use std::os::raw::c_void;
34
use std::pin::Pin;
45
use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
@@ -90,7 +91,7 @@ cpp! {{
9091

9192
~Waker() {
9293
rust!(QtDestroyFuture [future: *mut dyn Future<Output = ()> as "TraitObject"] {
93-
std::mem::drop(Box::from_raw(future))
94+
drop(Box::from_raw(future));
9495
});
9596
}
9697
};
@@ -160,7 +161,7 @@ pub unsafe fn wait_on_signal<Args: SignalArgArrayToTuple>(
160161
type Output = <Args as SignalArgArrayToTuple>::Tuple;
161162
fn poll(mut self: Pin<&mut Self>, ctx: &mut Context) -> Poll<Self::Output> {
162163
let state = &mut self.0;
163-
*state = match std::mem::replace(state, ConnectionFutureState::Invalid) {
164+
*state = match replace(state, ConnectionFutureState::Invalid) {
164165
ConnectionFutureState::Finished { result } => {
165166
return Poll::Ready(result);
166167
}
@@ -181,7 +182,7 @@ pub unsafe fn wait_on_signal<Args: SignalArgArrayToTuple>(
181182
for *mut ConnectionFutureState<Args>
182183
{
183184
unsafe fn apply(&mut self, a: *const *const c_void) {
184-
if let ConnectionFutureState::Started { mut handle, waker } = std::mem::replace(
185+
if let ConnectionFutureState::Started { mut handle, waker } = replace(
185186
&mut **self,
186187
ConnectionFutureState::Finished { result: Args::args_array_to_tuple(a) },
187188
) {

qmetaobject/src/lib.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
2323
```
2424
#[macro_use] extern crate cstr;
25-
extern crate qmetaobject;
2625
2726
use qmetaobject::*;
2827
@@ -88,7 +87,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8887
All the method are provided so you can just implement the QMetaType like this:
8988
9089
```rust
91-
# use qmetaobject::QMetaType;
90+
use qmetaobject::QMetaType;
91+
9292
#[derive(Default, Clone)]
9393
struct MyPoint(u32, u32);
9494
@@ -115,19 +115,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
115115
This can be done like so:
116116
117117
```
118-
# extern crate qmetaobject;
119-
# use qmetaobject::*;
120-
#[derive(QObject,Default)]
118+
use qmetaobject::*;
119+
# use std::cell::RefCell;
120+
121+
#[derive(QObject, Default)]
121122
struct MyAsyncObject {
122123
base: qt_base_class!(trait QObject),
123124
result: qt_property!(QString; NOTIFY result_changed),
124125
result_changed: qt_signal!(),
125126
recompute_result: qt_method!(fn recompute_result(&self, name: String) {
126127
let qptr = QPointer::from(&*self);
127-
let set_value = qmetaobject::queued_callback(move |val: QString| {
128-
qptr.as_pinned().map(|self_| {
129-
self_.borrow_mut().result = val;
130-
self_.borrow().result_changed();
128+
let set_value = queued_callback(move |val: QString| {
129+
qptr.as_pinned().map(|this| {
130+
this.borrow_mut().result = val;
131+
this.borrow().result_changed();
131132
});
132133
});
133134
std::thread::spawn(move || {
@@ -137,9 +138,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
137138
}).join();
138139
})
139140
}
140-
# let obj = std::cell::RefCell::new(MyAsyncObject::default());
141+
# let obj = RefCell::new(MyAsyncObject::default());
141142
# let mut engine = QmlEngine::new();
142-
# unsafe { qmetaobject::connect(
143+
# unsafe { connect(
143144
# QObject::cpp_construct(&obj),
144145
# obj.borrow().result_changed.to_cpp_representation(&*obj.borrow()),
145146
# || engine.quit()
@@ -157,9 +158,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
157158
#[macro_use]
158159
extern crate cpp;
159160

160-
#[allow(unused_imports)]
161-
#[macro_use]
162-
extern crate qmetaobject_impl;
163161
#[doc(hidden)]
164162
pub use qmetaobject_impl::*;
165163

@@ -173,7 +171,8 @@ pub use lazy_static::*;
173171
#[macro_export]
174172
macro_rules! qmetaobject_lazy_static { ($($t:tt)*) => { lazy_static!($($t)*) } }
175173

176-
use std::cell::RefCell;
174+
use std::cell::{RefCell, RefMut};
175+
use std::ffi::{CStr, CString};
177176
use std::os::raw::{c_char, c_void};
178177

179178
pub use qttypes;
@@ -440,11 +439,11 @@ impl<T: QObject + ?Sized> Clone for QPointer<T> {
440439
/// Same as std::cell::RefMut, but does not allow to move from
441440
pub struct QObjectRefMut<'b, T: QObject + ?Sized + 'b> {
442441
old_value: *mut c_void,
443-
inner: std::cell::RefMut<'b, T>,
442+
inner: RefMut<'b, T>,
444443
}
445444

446445
impl<'b, T: QObject + ?Sized> std::ops::Deref for QObjectRefMut<'b, T> {
447-
type Target = std::cell::RefMut<'b, T>;
446+
type Target = RefMut<'b, T>;
448447

449448
#[inline]
450449
fn deref(&self) -> &Self::Target {
@@ -543,7 +542,7 @@ impl<T: QObject + ?Sized> QObjectBox<T> {
543542
pub fn into_leaked_cpp_ptr<T: QObject>(obj: T) -> *mut c_void {
544543
let b = Box::new(RefCell::new(obj));
545544
let obj_ptr = unsafe { QObject::cpp_construct(&b) };
546-
std::boxed::Box::into_raw(b);
545+
Box::into_raw(b);
547546
obj_ptr
548547
}
549548

@@ -640,7 +639,8 @@ unsafe impl Send for QMetaObject {}
640639
/// The trait needs to be like the QObject trait, see the documentation of the QObject trait.
641640
///
642641
/// ```
643-
/// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject;
642+
/// use qmetaobject::*;
643+
///
644644
/// #[derive(QObject)]
645645
/// struct Foo {
646646
/// base : qt_base_class!(trait QObject),
@@ -670,7 +670,8 @@ macro_rules! qt_base_class {
670670
/// `ALIAS` followed by an identifier allow to give a different name than the actual field name.
671671
///
672672
/// ```
673-
/// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject;
673+
/// use qmetaobject::*;
674+
///
674675
/// #[derive(QObject)]
675676
/// struct Foo {
676677
/// base: qt_base_class!(trait QObject),
@@ -696,7 +697,8 @@ macro_rules! qt_property {
696697
/// Can be used within a struct that derives from QObject or QGadget
697698
///
698699
/// ```
699-
/// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject;
700+
/// use qmetaobject::*;
701+
///
700702
/// #[derive(QObject)]
701703
/// struct Foo {
702704
/// base: qt_base_class!(trait QObject),
@@ -726,7 +728,8 @@ macro_rules! qt_method {
726728
/// To be used within a struct that derives from QObject
727729
///
728730
/// ```
729-
/// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject;
731+
/// use qmetaobject::*;
732+
///
730733
/// #[derive(QObject)]
731734
/// struct Foo {
732735
/// base: qt_base_class!(trait QObject),
@@ -748,15 +751,16 @@ macro_rules! qt_signal {
748751
/// the IID
749752
///
750753
/// ```
751-
/// # #[macro_use] extern crate qmetaobject;
752-
/// # use qmetaobject::qtdeclarative::QQmlExtensionPlugin;
754+
/// use qmetaobject::*;
755+
/// # use std::ffi::CStr;
756+
///
753757
/// #[derive(Default, QObject)]
754758
/// struct MyPlugin {
755759
/// base: qt_base_class!(trait QQmlExtensionPlugin),
756760
/// plugin: qt_plugin!("org.qt-project.Qt.QQmlExtensionInterface/1.0")
757761
/// }
758762
/// # impl QQmlExtensionPlugin for MyPlugin {
759-
/// # fn register_types(&mut self, uri: &std::ffi::CStr) {}
763+
/// # fn register_types(&mut self, uri: &CStr) {}
760764
/// # }
761765
/// ```
762766
#[macro_export]
@@ -841,8 +845,8 @@ where
841845
/// callback will not be recieved.
842846
///
843847
/// ```
844-
/// # extern crate qmetaobject;
845-
/// # use qmetaobject::queued_callback;
848+
/// use qmetaobject::queued_callback;
849+
///
846850
/// let callback = queued_callback(|()| println!("hello from main thread"));
847851
/// std::thread::spawn(move || {callback(());}).join();
848852
/// ```
@@ -989,10 +993,9 @@ pub const USER_ROLE: i32 = 0x0100;
989993
/// ```
990994
/// then the following Rust code:
991995
/// ```
992-
/// # extern crate qmetaobject;
993-
/// # use qmetaobject::qrc;
996+
/// use qmetaobject::qrc;
994997
/// # // For maintainers: this is actually tested against real files.
995-
/// // private fn, and base directory shortcut
998+
/// // private fn, base directory shortcut
996999
/// qrc!(my_resource_1,
9971000
/// "tests/qml" as "foo1" {
9981001
/// "main.qml",
@@ -1016,6 +1019,7 @@ pub const USER_ROLE: i32 = 0x0100;
10161019
/// # fn use_resource(_r: &str) {
10171020
/// # // at the time of writing, it is the only way to test the existence of a resource.
10181021
/// # use qmetaobject::*;
1022+
/// #
10191023
/// # let mut engine = QmlEngine::new();
10201024
/// # let mut c = QmlComponent::new(&engine);
10211025
/// # c.load_url(QUrl::from(QString::from("qrc:/foo2/baz/Foo.qml")), CompilationMode::PreferSynchronous);

qmetaobject/src/listmodel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ where
223223
QVariant::default()
224224
}
225225
}
226-
fn role_names(&self) -> std::collections::HashMap<i32, QByteArray> {
226+
fn role_names(&self) -> HashMap<i32, QByteArray> {
227227
T::names().iter().enumerate().map(|(i, x)| (i as i32 + USER_ROLE, x.clone())).collect()
228228
}
229229
}

qmetaobject/src/log.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Logging facilities and forwarding
22
3+
use std::ffi::CStr;
34
use std::os::raw::c_char;
45

56
#[cfg(feature = "log")]
@@ -33,7 +34,7 @@ impl QMessageLogContext {
3334
if x.is_null() {
3435
return "";
3536
}
36-
std::ffi::CStr::from_ptr(x).to_str().unwrap()
37+
CStr::from_ptr(x).to_str().unwrap()
3738
}
3839
}
3940

@@ -46,7 +47,7 @@ impl QMessageLogContext {
4647
if x.is_null() {
4748
return "";
4849
}
49-
std::ffi::CStr::from_ptr(x).to_str().unwrap()
50+
CStr::from_ptr(x).to_str().unwrap()
5051
}
5152
}
5253

@@ -59,7 +60,7 @@ impl QMessageLogContext {
5960
if x.is_null() {
6061
return "";
6162
}
62-
std::ffi::CStr::from_ptr(x).to_str().unwrap()
63+
CStr::from_ptr(x).to_str().unwrap()
6364
}
6465
}
6566
}

0 commit comments

Comments
 (0)