Skip to content

Commit a70fa14

Browse files
committed
Some stricter linting + resultant cleanup.
1 parent f5da466 commit a70fa14

File tree

9 files changed

+45
-33
lines changed

9 files changed

+45
-33
lines changed

vgtk/src/callback.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::rc::Rc;
55
pub struct Callback<A>(pub(crate) Rc<dyn Fn(A)>);
66

77
impl<A: Debug> Callback<A> {
8+
/// Send a value to the callback.
89
pub fn send(&self, value: A) {
910
(self.0)(value)
1011
}
@@ -23,7 +24,7 @@ impl<A> PartialEq for Callback<A> {
2324
}
2425

2526
impl<A> Debug for Callback<A> {
26-
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
27+
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
2728
write!(f, "Callback()")
2829
}
2930
}

vgtk/src/component.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub(crate) enum ComponentMessage<C: Component> {
112112
}
113113

114114
impl<C: Component> Debug for ComponentMessage<C> {
115-
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
115+
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
116116
match self {
117117
ComponentMessage::Update(msg) => write!(
118118
f,
@@ -210,12 +210,12 @@ where
210210
(self.sender, self.task)
211211
}
212212

213-
pub fn object(&self) -> Object {
213+
pub(crate) fn object(&self) -> Object {
214214
self.task.ui_state.as_ref().unwrap().object().clone()
215215
}
216216
}
217217

218-
pub struct ComponentTask<C, P>
218+
pub(crate) struct ComponentTask<C, P>
219219
where
220220
C: Component,
221221
P: Component,
@@ -247,7 +247,7 @@ where
247247
})
248248
}
249249

250-
pub fn process(&mut self, ctx: &mut Context) -> Poll<()> {
250+
pub(crate) fn process(&mut self, ctx: &mut Context<'_>) -> Poll<()> {
251251
let mut render = false;
252252
loop {
253253
let next = Stream::poll_next(self.channel.as_mut(), ctx);
@@ -332,7 +332,7 @@ where
332332
}
333333
}
334334

335-
pub fn object(&self) -> Option<Object> {
335+
pub(crate) fn object(&self) -> Option<Object> {
336336
self.ui_state.as_ref().map(|state| state.object().clone())
337337
}
338338

@@ -417,7 +417,7 @@ where
417417
{
418418
type Output = ();
419419

420-
fn poll(self: Pin<&mut Self>, ctx: &mut Context) -> Poll<Self::Output> {
420+
fn poll(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Self::Output> {
421421
LOCAL_CONTEXT.with(|key| {
422422
*key.write().unwrap() = LocalContext {
423423
parent_scope: self.parent_scope.as_ref().map(|scope| scope.clone().into()),

vgtk/src/ext.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//! It is generally a good idea to `use vgtk::ext::*;` wherever you're using the
44
//! `gtk!` macro.
55
6+
#![allow(missing_docs)]
7+
68
use gdk_pixbuf::Pixbuf;
79
use gio::{Action, ActionExt, ApplicationFlags};
810
use glib::{GString, IsA, Object, ObjectExt};
@@ -14,7 +16,13 @@ use gtk::{
1416
use colored::Colorize;
1517
use log::trace;
1618

19+
/// Helper trait for `Application`.
1720
pub trait ApplicationHelpers: GtkApplicationExt {
21+
/// Construct a new `Application` and panic if it fails.
22+
///
23+
/// This is like `Application::new`, but returns an `Application` instead of
24+
/// an `Option<Application>`, so you can use it as a constructor in the `gtk!`
25+
/// macro.
1826
fn new_unwrap(application_id: Option<&str>, flags: ApplicationFlags) -> Application {
1927
Application::new(application_id, flags).expect("unable to create Application object")
2028
}
@@ -47,6 +55,7 @@ pub trait ApplicationHelpers: GtkApplicationExt {
4755

4856
impl<A> ApplicationHelpers for A where A: GtkApplicationExt {}
4957

58+
/// Helper trait for `ApplicationWindow`.
5059
pub trait ApplicationWindowHelpers: ApplicationWindowExt + GtkWindowExt + IsA<Window> {
5160
fn get_child_accels<P: IsA<Action>>(&self, action: &P) -> Vec<GString> {
5261
let app = self
@@ -99,6 +108,7 @@ pub trait ApplicationWindowHelpers: ApplicationWindowExt + GtkWindowExt + IsA<Wi
99108

100109
impl<A> ApplicationWindowHelpers for A where A: ApplicationWindowExt + GtkWindowExt + IsA<Window> {}
101110

111+
/// Helper trait for `Window`.
102112
pub trait WindowExtHelpers: GtkWindowExt {
103113
fn get_default_height(&self) -> i32 {
104114
self.get_property_default_height()
@@ -143,6 +153,7 @@ pub trait WindowExtHelpers: GtkWindowExt {
143153

144154
impl<A> WindowExtHelpers for A where A: GtkWindowExt {}
145155

156+
/// Helper trait for `Box`.
146157
pub trait BoxExtHelpers: BoxExt {
147158
fn get_child_center_widget(&self, _child: &Object) -> bool {
148159
// Always compare true, it's all taken care of in add_child().
@@ -156,6 +167,7 @@ pub trait BoxExtHelpers: BoxExt {
156167

157168
impl<A> BoxExtHelpers for A where A: BoxExt {}
158169

170+
/// Helper trait for `Image`.
159171
pub trait ImageExtHelpers: ImageExt {
160172
fn set_pixbuf(&self, pixbuf: Option<Pixbuf>) {
161173
self.set_from_pixbuf(pixbuf.as_ref());
@@ -164,6 +176,7 @@ pub trait ImageExtHelpers: ImageExt {
164176

165177
impl<A> ImageExtHelpers for A where A: ImageExt {}
166178

179+
/// Helper trait for `Label`.
167180
pub trait LabelExtHelpers: LabelExt {
168181
fn get_markup(&self) -> Option<GString> {
169182
self.get_label()

vgtk/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! A declarative UI framework built on [GTK] and [Gtk-rs].
22
//!
3+
//! ## Overview
4+
//!
5+
//!
6+
//!
37
//! ## Show Me!
48
//!
59
//! ```rust,no_run
@@ -58,6 +62,11 @@
5862
//! [GTK]: https://www.gtk.org/
5963
//! [Gtk-rs]: https://gtk-rs.org/
6064
65+
#![forbid(rust_2018_idioms)]
66+
#![deny(nonstandard_style, unsafe_code)]
67+
#![warn(unreachable_pub, missing_docs)]
68+
#![allow(clippy::needless_doctest_main)]
69+
6170
mod callback;
6271
mod component;
6372
pub mod ext;

vgtk/src/scope.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<C: 'static + Component> From<Scope<C>> for AnyScope {
101101
let drop = |ptr: &mut AtomicPtr<()>| {
102102
let ptr = ptr.swap(std::ptr::null_mut(), Ordering::SeqCst);
103103
if !ptr.is_null() {
104-
#[allow(clippy::cast_ptr_alignment)]
104+
#[allow(unsafe_code)]
105105
let scope = unsafe { Box::from_raw(ptr as *mut Scope<C>) };
106106
std::mem::drop(scope)
107107
}
@@ -121,25 +121,11 @@ impl Drop for AnyScope {
121121
}
122122

123123
impl AnyScope {
124-
// pub fn try_into<C: 'static + Component>(self) -> Result<Box<Scope<C>>, Self> {
125-
// if TypeId::of::<C::Properties>() == self.type_id {
126-
// let ptr = self.ptr.swap(std::ptr::null_mut(), Ordering::SeqCst);
127-
// if ptr.is_null() {
128-
// panic!("AnyScope: can't consume dropped value")
129-
// } else {
130-
// #[allow(clippy::cast_ptr_alignment)]
131-
// Ok(unsafe { Box::from_raw(ptr as *mut Scope<C>) })
132-
// }
133-
// } else {
134-
// Err(self)
135-
// }
136-
// }
137-
138-
pub fn try_get<C: 'static + Component>(&self) -> Option<&'static Scope<C>> {
124+
pub(crate) fn try_get<C: 'static + Component>(&self) -> Option<&'static Scope<C>> {
139125
if TypeId::of::<C::Properties>() == self.type_id {
140-
#[allow(clippy::cast_ptr_alignment)]
126+
#[allow(unsafe_code)]
141127
unsafe {
142-
(self.ptr.load(Ordering::SeqCst) as *const Scope<C>).as_ref()
128+
(self.ptr.load(Ordering::Relaxed) as *const Scope<C>).as_ref()
143129
}
144130
} else {
145131
None

vgtk/src/vdom/component_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<Model: 'static + Component> ComponentState<Model> {
6868
}
6969
}
7070

71-
pub struct SubcomponentState<Model: Component> {
71+
pub(crate) struct SubcomponentState<Model: Component> {
7272
channel: UnboundedSender<ComponentMessage<Model>>,
7373
}
7474

vgtk/src/vdom/gtk_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::component::Component;
1212
use crate::scope::Scope;
1313
use crate::vnode::{VHandler, VNode, VObject, VProperty};
1414

15-
pub struct GtkState<Model: Component> {
16-
pub object: Object,
15+
pub(crate) struct GtkState<Model: Component> {
16+
pub(crate) object: Object,
1717
handlers: HashMap<(&'static str, &'static str), SignalHandlerId>,
1818
children: Vec<State<Model>>,
1919
}

vgtk/src/vdom/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use crate::scope::Scope;
66
use crate::vnode::VNode;
77

88
mod component_state;
9-
pub use component_state::ComponentState;
9+
pub(crate) use component_state::ComponentState;
1010

1111
mod gtk_state;
1212
use gtk_state::GtkState;
1313

14-
pub enum State<Model: Component> {
14+
pub(crate) enum State<Model: Component> {
1515
Gtk(GtkState<Model>),
1616
Component(ComponentState<Model>),
1717
}
@@ -88,15 +88,15 @@ impl<Model: 'static + Component> State<Model> {
8888
}
8989

9090
/// Get the Glib `Object` represented by this state.
91-
pub fn object(&self) -> &Object {
91+
pub(crate) fn object(&self) -> &Object {
9292
match self {
9393
State::Gtk(state) => &state.object,
9494
State::Component(state) => &state.object,
9595
}
9696
}
9797

9898
/// Get the Gtk `Widget` represented by this state, if it has a `Widget`.
99-
pub fn widget(&self) -> Option<&Widget> {
99+
pub(crate) fn widget(&self) -> Option<&Widget> {
100100
match self {
101101
State::Gtk(state) => state.object.downcast_ref::<Widget>(),
102102
State::Component(state) => state.object.downcast_ref::<Widget>(),

vgtk/src/vnode/component.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ impl AnyProps {
4545
TypeId::of::<Props>()
4646
)
4747
}
48-
unsafe { *Box::from_raw(self.data as *mut Props) }
48+
#[allow(unsafe_code)]
49+
unsafe {
50+
*Box::from_raw(self.data as *mut Props)
51+
}
4952
}
5053
}
5154

0 commit comments

Comments
 (0)