diff --git a/examples/dashboard/src/widgets/map.rs b/examples/dashboard/src/widgets/map.rs index e0a5b61..0ac48ba 100644 --- a/examples/dashboard/src/widgets/map.rs +++ b/examples/dashboard/src/widgets/map.rs @@ -108,7 +108,7 @@ impl Map { if let Some(controller) = controller.into() { controller.bind(channel.clone()); } - Map { + Self { channel, camera: camera.clone(), } @@ -209,7 +209,7 @@ impl MapState { channel: Channel, sender: Sender, ) -> Self { - MapState { + Self { texture, channel, sender, @@ -245,7 +245,7 @@ unsafe impl Send for RenderMap {} impl RenderMap { pub fn new(receiver: Receiver) -> Self { - RenderMap { + Self { receiver, map: None, last_size: None, diff --git a/examples/dashboard/src/widgets/metrics.rs b/examples/dashboard/src/widgets/metrics.rs index 0bb5699..48ebc85 100644 --- a/examples/dashboard/src/widgets/metrics.rs +++ b/examples/dashboard/src/widgets/metrics.rs @@ -38,7 +38,7 @@ impl Metric { color: impl Into, value: f32, ) -> Self { - Metric { + Self { level, suffix: suffix.as_ref().to_string(), description: description.as_ref().to_string(), @@ -124,7 +124,7 @@ struct MetricState { impl MetricState { pub fn new(level: i32, value: f32) -> Self { - MetricState { + Self { animation: None, level: Tween::new(0, level), value: Tween::new(0.0, value), @@ -149,7 +149,7 @@ pub struct Metrics {} impl Metrics { pub fn new() -> Self { - Metrics {} + Self {} } } diff --git a/examples/dashboard/src/widgets/navigation.rs b/examples/dashboard/src/widgets/navigation.rs index 5b8644c..bb3a20e 100644 --- a/examples/dashboard/src/widgets/navigation.rs +++ b/examples/dashboard/src/widgets/navigation.rs @@ -31,7 +31,7 @@ pub struct Navigation {} impl Navigation { pub fn new() -> Self { - Navigation {} + Self {} } } @@ -68,7 +68,7 @@ struct NavigationState { impl NavigationState { pub fn new() -> Self { - NavigationState { + Self { map: MapController::new(), } } diff --git a/examples/dashboard/src/widgets/sensors.rs b/examples/dashboard/src/widgets/sensors.rs index e4854fd..97cc291 100644 --- a/examples/dashboard/src/widgets/sensors.rs +++ b/examples/dashboard/src/widgets/sensors.rs @@ -28,7 +28,7 @@ pub struct Sensor { impl Sensor { pub fn new(level: f32) -> Self { - Sensor { level } + Self { level } } } @@ -81,7 +81,7 @@ struct SensorState { impl SensorState { pub fn new() -> Self { - SensorState { animation: None } + Self { animation: None } } pub fn animation(&self) -> Option { @@ -94,7 +94,7 @@ pub struct Sensors {} impl Sensors { pub fn new() -> Self { - Sensors {} + Self {} } fn build_sensor_data(&self, title: impl AsRef) -> impl Widget { diff --git a/examples/dashboard/src/widgets/sidebar.rs b/examples/dashboard/src/widgets/sidebar.rs index ea6ebac..e4f092d 100644 --- a/examples/dashboard/src/widgets/sidebar.rs +++ b/examples/dashboard/src/widgets/sidebar.rs @@ -34,7 +34,7 @@ pub struct Sidebar {} impl Sidebar { pub fn new() -> Self { - Sidebar {} + Self {} } fn build_button( @@ -151,7 +151,7 @@ struct SidebarState { impl SidebarState { pub fn new() -> Self { - SidebarState { + Self { selected_button: Button::Earth, } } diff --git a/examples/dashboard/src/widgets/topbar.rs b/examples/dashboard/src/widgets/topbar.rs index 984a3c0..e4084e3 100644 --- a/examples/dashboard/src/widgets/topbar.rs +++ b/examples/dashboard/src/widgets/topbar.rs @@ -41,7 +41,7 @@ impl Tab { title: impl AsRef, selected: bool, ) -> Self { - Tab { + Self { title: title.as_ref().to_string(), selected, } @@ -151,7 +151,7 @@ struct TabState { impl TabState { pub fn new(selected: bool) -> Self { - TabState { + Self { animation: None, selected, } @@ -167,7 +167,7 @@ pub struct Topbar {} impl Topbar { pub fn new() -> Self { - Topbar {} + Self {} } fn build_tab( @@ -273,7 +273,7 @@ struct TopbarState { impl TopbarState { pub fn new() -> Self { - TopbarState { + Self { selected_button: Button::RealTime, } } diff --git a/terramach/graphics/src/gl/android_context.rs b/terramach/graphics/src/gl/android_context.rs index 3a5e60e..ca4d1ee 100644 --- a/terramach/graphics/src/gl/android_context.rs +++ b/terramach/graphics/src/gl/android_context.rs @@ -71,7 +71,7 @@ impl Context { pub fn new_shared(&mut self) -> Self { let config = egl::android_choose_config(self.inner.display); - Context { + Self { inner: Rc::new(EGLContext { owner: true, context: egl::android_new_context(self.inner.display, config), @@ -100,7 +100,7 @@ impl Context { impl Clone for Context { fn clone(&self) -> Self { - Context { + Self { inner: self.inner.clone(), guard: None, } @@ -126,7 +126,7 @@ impl ContextGuard { context.inner.context, ); debug_assert!(result); - ContextGuard { + Self { current_context, current_read_surface, current_draw_surface, diff --git a/terramach/graphics/src/gl/mac_context.rs b/terramach/graphics/src/gl/mac_context.rs index e3e0a7e..c5014c1 100644 --- a/terramach/graphics/src/gl/mac_context.rs +++ b/terramach/graphics/src/gl/mac_context.rs @@ -102,7 +102,7 @@ impl Context { impl Clone for Context { fn clone(&self) -> Self { - Context { + Self { inner: self.inner.clone(), guard: None, } diff --git a/terramach/ui/animation.rs b/terramach/ui/animation.rs index 9eacc3f..8074339 100644 --- a/terramach/ui/animation.rs +++ b/terramach/ui/animation.rs @@ -64,7 +64,7 @@ impl Animation { D: 'static + Driver, A: 'static + Animated, { - Animation { + Self { driver: Box::new(driver), animated: Box::new(animated), interpolation: None, @@ -115,7 +115,7 @@ pub struct DurationDriver { impl DurationDriver { pub fn new(duration: Duration) -> Self { - DurationDriver { + Self { timestamp: None, value: 0.0, duration, @@ -167,7 +167,7 @@ pub struct Tween> { impl> Tween { pub fn new(begin: impl Into, end: impl Into) -> Self { - Tween { + Self { begin: begin.into(), end: end.into(), } @@ -188,7 +188,7 @@ impl> Animated for Tween { impl> From<(T, T)> for Tween { fn from(values: (T, T)) -> Self { - Tween::new(values.0, values.1) + Self::new(values.0, values.1) } } diff --git a/terramach/ui/common/index_pool.rs b/terramach/ui/common/index_pool.rs index 5f505c4..fc357a1 100644 --- a/terramach/ui/common/index_pool.rs +++ b/terramach/ui/common/index_pool.rs @@ -24,7 +24,7 @@ pub struct IndexPool { impl IndexPool { pub fn new() -> Self { - IndexPool { + Self { current_index: 0, free_indexes: Vec::new(), } diff --git a/terramach/ui/common/tree.rs b/terramach/ui/common/tree.rs index db36d80..9599afd 100644 --- a/terramach/ui/common/tree.rs +++ b/terramach/ui/common/tree.rs @@ -31,7 +31,7 @@ struct Node { impl Node { pub fn new(id: Id, data: impl Into>) -> Self { - Node { + Self { id, inner: data.into(), } @@ -75,7 +75,7 @@ impl Tree { let root = indices.take(); let mut nodes = HashMap::new(); nodes.insert(root, Node::new(root, None)); - Tree { + Self { ids: indices, root, nodes, diff --git a/terramach/ui/event.rs b/terramach/ui/event.rs index 65a19a5..a1afdcd 100644 --- a/terramach/ui/event.rs +++ b/terramach/ui/event.rs @@ -59,7 +59,7 @@ pub struct EventContext { impl EventContext { pub fn new(event: Event) -> Self { - EventContext { + Self { need_layout: false, need_paint: false, need_build: false, @@ -122,7 +122,7 @@ pub type AppEvents = Events; impl Default for AppEvents { fn default() -> Self { - AppEvents::new() + Self::new() } } @@ -135,7 +135,7 @@ pub struct Events { impl Events { pub fn new() -> Self { - Events { + Self { queue: Default::default(), } } diff --git a/terramach/ui/gesture.rs b/terramach/ui/gesture.rs index d1858c0..7c11e83 100644 --- a/terramach/ui/gesture.rs +++ b/terramach/ui/gesture.rs @@ -41,7 +41,7 @@ pub struct TapGesture { impl TapGesture { pub fn new(touches_count: usize, tap_count: usize) -> Self { - TapGesture { + Self { touches_count, tap_count, start_touches_count: 0, @@ -82,13 +82,13 @@ impl TapGesture { impl Default for TapGesture { fn default() -> Self { - TapGesture::new(1, 1) + Self::new(1, 1) } } impl Clone for TapGesture { fn clone(&self) -> Self { - TapGesture::new(self.touches_count, self.tap_count) + Self::new(self.touches_count, self.tap_count) } } @@ -109,7 +109,7 @@ pub struct PanGesture { impl PanGesture { pub fn new(minimum_touches: usize, maximum_touches: usize) -> Self { - PanGesture { + Self { minimum_touches, maximum_touches, start_location: None, @@ -118,7 +118,7 @@ impl PanGesture { } pub fn limit(touches_count: usize) -> Self { - PanGesture::new(touches_count, touches_count) + Self::new(touches_count, touches_count) } pub fn is_active(&self) -> bool { @@ -172,13 +172,13 @@ impl PanGesture { impl Default for PanGesture { fn default() -> Self { - PanGesture::new(1, 10) + Self::new(1, 10) } } impl Clone for PanGesture { fn clone(&self) -> Self { - PanGesture::new(self.minimum_touches, self.maximum_touches) + Self::new(self.minimum_touches, self.maximum_touches) } } @@ -222,7 +222,7 @@ pub struct PinchGesture { impl PinchGesture { pub fn new() -> Self { - PinchGesture { + Self { state: PinchGestureState::Possible, start_distance: None, center_location: None, @@ -304,12 +304,12 @@ impl PinchGesture { impl Default for PinchGesture { fn default() -> Self { - PinchGesture::new() + Self::new() } } impl Clone for PinchGesture { fn clone(&self) -> Self { - PinchGesture::new() + Self::new() } } diff --git a/terramach/ui/gpu/frame.rs b/terramach/ui/gpu/frame.rs index 454170e..e63f5f5 100644 --- a/terramach/ui/gpu/frame.rs +++ b/terramach/ui/gpu/frame.rs @@ -27,7 +27,7 @@ pub struct Frame { impl Frame { pub fn new(layers: &LayerTree) -> Self { - Frame { + Self { layers: layers.clone(), } } diff --git a/terramach/ui/gpu/gl_texture.rs b/terramach/ui/gpu/gl_texture.rs index e617b11..727837f 100644 --- a/terramach/ui/gpu/gl_texture.rs +++ b/terramach/ui/gpu/gl_texture.rs @@ -34,7 +34,7 @@ impl<'a> RenderContext<'a> { gl: &'a mut gl::Gl, size: ISize, ) -> Self { - RenderContext { + Self { gl, size, } @@ -67,7 +67,7 @@ impl<'a> PrerollContext<'a> { texture: TextureId, size: ISize, ) -> Self { - PrerollContext { + Self { pixel_ratio, pipeline, gl, @@ -150,7 +150,7 @@ impl Texture { gl::BindFramebuffer(gl::FRAMEBUFFER, frame_buffer); gl::FramebufferTexture2D(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, texture, 0); } - Texture { + Self { gl, gl_context, frame_buffer, diff --git a/terramach/ui/gpu/pipeline.rs b/terramach/ui/gpu/pipeline.rs index 1b6e40f..4028d8c 100644 --- a/terramach/ui/gpu/pipeline.rs +++ b/terramach/ui/gpu/pipeline.rs @@ -48,7 +48,7 @@ impl Pipeline { receiver, ); std::thread::spawn(move || render_pipeline.render()); - Pipeline { sender } + Self { sender } } pub fn resize(&mut self, display_size: impl Into) { @@ -73,7 +73,7 @@ pub struct SharedPipeline { impl SharedPipeline { fn new(sender: &Sender) -> Self { - SharedPipeline { + Self { sender: sender.clone(), } } @@ -113,7 +113,7 @@ impl RenderPipeline { sender: Sender, receiver: Receiver, ) -> Self { - RenderPipeline { + Self { vsync, display, sender, diff --git a/terramach/ui/gpu/texture.rs b/terramach/ui/gpu/texture.rs index 9137768..fc152f7 100644 --- a/terramach/ui/gpu/texture.rs +++ b/terramach/ui/gpu/texture.rs @@ -27,7 +27,7 @@ pub struct TextureContext {} impl TextureContext { pub fn new() -> Self { - TextureContext {} + Self {} } } @@ -38,7 +38,7 @@ pub struct TextureRegistry { impl TextureRegistry { pub fn new() -> Self { - TextureRegistry { + Self { textures: HashMap::new(), } } diff --git a/terramach/ui/hit.rs b/terramach/ui/hit.rs index 9402408..b34e38d 100644 --- a/terramach/ui/hit.rs +++ b/terramach/ui/hit.rs @@ -33,7 +33,7 @@ impl EventResponder { transformation: impl Into>, cursor: impl Into>, ) -> Self { - EventResponder { + Self { widget, transformation: transformation.into(), cursor: cursor.into(), @@ -90,7 +90,7 @@ pub struct HitTestContext { impl HitTestContext { pub fn new(size: impl Into, location: impl Into) -> Self { - HitTestContext { + Self { size: size.into(), location: location.into(), transformation: Matrix::default(), diff --git a/terramach/ui/keys.rs b/terramach/ui/keys.rs index 7b8bcd8..f1afc1c 100644 --- a/terramach/ui/keys.rs +++ b/terramach/ui/keys.rs @@ -35,7 +35,7 @@ pub struct KeyModifiers(FlagSet); impl KeyModifiers { pub fn new(modifiers: impl Into>) -> Self { - KeyModifiers(modifiers.into()) + Self(modifiers.into()) } pub fn clear_all(&mut self) { @@ -217,7 +217,7 @@ impl HitKey { action: KeyAction, modifiers: KeyModifiers, ) -> Self { - HitKey { + Self { character: character.into(), key: Key::from(scan_code), scan_code, @@ -260,7 +260,7 @@ pub struct KeyTracker { impl KeyTracker { pub fn new() -> Self { - KeyTracker { + Self { modifiers: KeyModifiers::default(), scan_code: None, keys: HashMap::new(), diff --git a/terramach/ui/layers/clip_rect.rs b/terramach/ui/layers/clip_rect.rs index 13e0e71..d2e8c01 100644 --- a/terramach/ui/layers/clip_rect.rs +++ b/terramach/ui/layers/clip_rect.rs @@ -27,7 +27,7 @@ pub struct ClipRectLayer { impl ClipRectLayer { pub fn new(clip_rect: impl Into) -> Self { - ClipRectLayer { + Self { clip_rect: clip_rect.into(), } } diff --git a/terramach/ui/layers/clip_rrect.rs b/terramach/ui/layers/clip_rrect.rs index b9c783d..d55bfa8 100644 --- a/terramach/ui/layers/clip_rrect.rs +++ b/terramach/ui/layers/clip_rrect.rs @@ -27,7 +27,7 @@ pub struct ClipRRectLayer { impl ClipRRectLayer { pub fn new(clip_rrect: impl Into) -> Self { - ClipRRectLayer { + Self { clip_rrect: clip_rrect.into(), } } diff --git a/terramach/ui/layers/container.rs b/terramach/ui/layers/container.rs index bbd16c7..0b28c74 100644 --- a/terramach/ui/layers/container.rs +++ b/terramach/ui/layers/container.rs @@ -27,7 +27,7 @@ pub struct ContainerLayer { impl ContainerLayer { pub fn new() -> Self { - ContainerLayer { layers: Vec::new() } + Self { layers: Vec::new() } } pub fn is_empty(&self) -> bool { diff --git a/terramach/ui/layers/draw.rs b/terramach/ui/layers/draw.rs index 2d7c465..8208212 100644 --- a/terramach/ui/layers/draw.rs +++ b/terramach/ui/layers/draw.rs @@ -37,7 +37,7 @@ impl<'a> DrawContext<'a> { textures: &'a mut TextureRegistry, draw_children: &'a mut F, ) -> Self where F: FnMut(&mut Canvas, &mut TextureRegistry) { - DrawContext { + Self { size: size.into(), canvas, textures, diff --git a/terramach/ui/layers/offset.rs b/terramach/ui/layers/offset.rs index 9192409..40e5e58 100644 --- a/terramach/ui/layers/offset.rs +++ b/terramach/ui/layers/offset.rs @@ -27,7 +27,7 @@ pub struct OffsetLayer { impl OffsetLayer { pub fn new(offset: impl Into) -> Self { - OffsetLayer { + Self { offset: offset.into(), } } diff --git a/terramach/ui/layers/opacity.rs b/terramach/ui/layers/opacity.rs index 97f582d..ac09aeb 100644 --- a/terramach/ui/layers/opacity.rs +++ b/terramach/ui/layers/opacity.rs @@ -27,7 +27,7 @@ pub struct OpacityLayer { impl OpacityLayer { pub fn new(opacity: impl Into) -> Self { - OpacityLayer { + Self { opacity: opacity.into(), } } diff --git a/terramach/ui/layers/picture.rs b/terramach/ui/layers/picture.rs index 4355225..8d0044d 100644 --- a/terramach/ui/layers/picture.rs +++ b/terramach/ui/layers/picture.rs @@ -31,7 +31,7 @@ unsafe impl Send for PictureLayer {} impl PictureLayer { pub fn new(picture: Picture) -> Self { - PictureLayer { + Self { picture: Arc::new(picture), } } diff --git a/terramach/ui/layers/texture.rs b/terramach/ui/layers/texture.rs index 69326ca..f093980 100644 --- a/terramach/ui/layers/texture.rs +++ b/terramach/ui/layers/texture.rs @@ -26,7 +26,7 @@ pub struct TextureLayer { impl TextureLayer { pub fn new(texture_id: impl Into) -> Self { - TextureLayer { + Self { texture_id: texture_id.into(), } } diff --git a/terramach/ui/layers/tree.rs b/terramach/ui/layers/tree.rs index 6a43f22..d633f80 100644 --- a/terramach/ui/layers/tree.rs +++ b/terramach/ui/layers/tree.rs @@ -37,7 +37,7 @@ impl LayerKey { layers: impl Into>>, leaf_layers: impl Into>>, ) -> Self { - LayerKey { + Self { size: size.into(), layers: layers.into().unwrap_or_default(), leaf_layers: leaf_layers.into().unwrap_or_default(), @@ -54,7 +54,7 @@ pub struct LayerTree { impl LayerTree { pub fn new() -> Self { - LayerTree { + Self { tree: Tree::new(), keys: HashMap::new(), layer_key: HashMap::new(), diff --git a/terramach/ui/layout.rs b/terramach/ui/layout.rs index 814a8c0..cd5affd 100644 --- a/terramach/ui/layout.rs +++ b/terramach/ui/layout.rs @@ -31,7 +31,7 @@ pub enum Fit { impl Default for Fit { fn default() -> Self { - Fit::Contain + Self::Contain } } @@ -135,7 +135,7 @@ impl Constraints { minimum_size: impl Into>, maximum_size: impl Into>, ) -> Self { - Constraints { + Self { minimum_size: minimum_size.into().unwrap_or(Size::new_empty()), maximum_size: maximum_size.into().unwrap_or(Size::new_unbound()), } @@ -143,7 +143,7 @@ impl Constraints { pub fn new_tight(size: impl Into) -> Self { let size = size.into(); - Constraints { + Self { minimum_size: size, maximum_size: size, } @@ -151,7 +151,7 @@ impl Constraints { pub fn new_loose(size: impl Into) -> Self { let size = size.into(); - Constraints { + Self { minimum_size: Size::new_empty(), maximum_size: size, } @@ -175,7 +175,7 @@ impl Constraints { impl From<(Size, Size)> for Constraints { fn from(size: (Size, Size)) -> Self { - Constraints::new(size.0, size.1) + Self::new(size.0, size.1) } } @@ -196,7 +196,7 @@ impl<'a> LayoutContext<'a> { ) -> Self where C: Fn(usize) -> Option, L: FnMut(Id, &Constraints) -> Option { - LayoutContext { + Self { constraints: constraints .into() .unwrap_or(Constraints::new_loose(Size::new_unbound())), diff --git a/terramach/ui/paint.rs b/terramach/ui/paint.rs index 6640908..be843a1 100644 --- a/terramach/ui/paint.rs +++ b/terramach/ui/paint.rs @@ -31,7 +31,7 @@ pub struct PaintContext { impl PaintContext { pub fn new(size: impl Into) -> Self { - PaintContext { + Self { recorder: None, size: size.into(), painted_children: false, diff --git a/terramach/ui/platform/android/app.rs b/terramach/ui/platform/android/app.rs index 884cbaa..c42cee9 100644 --- a/terramach/ui/platform/android/app.rs +++ b/terramach/ui/platform/android/app.rs @@ -32,7 +32,7 @@ pub struct App { impl App { pub fn new() -> Self { - App { + Self { content: None, } } diff --git a/terramach/ui/platform/android/clipboard.rs b/terramach/ui/platform/android/clipboard.rs index 9c526c7..07aaae2 100644 --- a/terramach/ui/platform/android/clipboard.rs +++ b/terramach/ui/platform/android/clipboard.rs @@ -33,13 +33,13 @@ impl From for ClipboardContent { impl From<&str> for ClipboardContent { fn from(data: &str) -> Self { - ClipboardContent::from(data.to_string()) + Self::from(data.to_string()) } } impl From<&String> for ClipboardContent { fn from(data: &String) -> Self { - ClipboardContent::from(data.clone()) + Self::from(data.clone()) } } @@ -66,6 +66,6 @@ impl Clipboard { impl Default for Clipboard { fn default() -> Self { - Clipboard::new() + Self::new() } } diff --git a/terramach/ui/platform/android/cursor.rs b/terramach/ui/platform/android/cursor.rs index c95b326..ab315f2 100644 --- a/terramach/ui/platform/android/cursor.rs +++ b/terramach/ui/platform/android/cursor.rs @@ -24,7 +24,7 @@ pub enum Cursor { impl Default for Cursor { fn default() -> Self { - Cursor::Arrow + Self::Arrow } } @@ -33,7 +33,7 @@ pub struct Cursors {} impl Cursors { pub fn new() -> Self { - Cursors {} + Self {} } pub fn push(&mut self, cursor: impl Into>) { diff --git a/terramach/ui/platform/android/run_loop.rs b/terramach/ui/platform/android/run_loop.rs index 5284292..591cf3b 100644 --- a/terramach/ui/platform/android/run_loop.rs +++ b/terramach/ui/platform/android/run_loop.rs @@ -56,13 +56,13 @@ impl Fd { impl From for Fd { fn from(fd: i32) -> Self { - Fd(AtomicI32::new(fd)) + Self(AtomicI32::new(fd)) } } impl Clone for Fd { fn clone(&self) -> Self { - Fd::from(self.handle()) + Self::from(self.handle()) } } @@ -106,7 +106,7 @@ impl RunLoopTimer { &new_value, null_mut(), ), -1, "Failed to arm a timer"); - RunLoopTimer { + Self { fd: Rc::new(Fd::from(fd)), } } @@ -150,7 +150,7 @@ impl SharedRunLoop { unsafe { bindings::ALooper_acquire(run_loop.inner); } - SharedRunLoop { + Self { looper: run_loop.inner, running: run_loop.running.clone(), timer: run_loop.timer.clone(), @@ -178,7 +178,7 @@ impl Clone for SharedRunLoop { unsafe { bindings::ALooper_acquire(self.looper); } - SharedRunLoop { + Self { looper: self.looper, running: self.running.clone(), timer: self.timer.clone(), @@ -209,7 +209,7 @@ impl RunLoop { unsafe { let looper = bindings::ALooper_forThread(); assert!(!looper.is_null(), "Looper is not available on current thread"); - RunLoop::from_looper(looper) + Self::from_looper(looper) } } @@ -217,7 +217,7 @@ impl RunLoop { unsafe { let looper = bindings::ALooper_prepare(bindings::ALOOPER_PREPARE_ALLOW_NON_CALLBACKS as c_int); assert!(!looper.is_null(), "Failed to prepare a looper on current thread"); - RunLoop::from_looper(looper) + Self::from_looper(looper) } } @@ -236,7 +236,7 @@ impl RunLoop { ), -1, "Failed to add a timer", ); - RunLoop { + Self { inner: looper, running: Rc::new(AtomicBool::new(false)), last_handle: RunLoopHandle::default(), diff --git a/terramach/ui/platform/android/view.rs b/terramach/ui/platform/android/view.rs index b5493d0..9d1b87a 100644 --- a/terramach/ui/platform/android/view.rs +++ b/terramach/ui/platform/android/view.rs @@ -37,7 +37,7 @@ struct Egl { impl Egl { pub fn new(display: egl::EGLDisplay, surface: egl::EGLSurface, context: egl::EGLContext) -> Self { - Egl { + Self { display, surface, context, diff --git a/terramach/ui/platform/darwin/clipboard.rs b/terramach/ui/platform/darwin/clipboard.rs index 0f2a92a..7df1916 100644 --- a/terramach/ui/platform/darwin/clipboard.rs +++ b/terramach/ui/platform/darwin/clipboard.rs @@ -45,7 +45,7 @@ impl ClipboardContent { impl From for ClipboardContent { fn from(data: String) -> Self { - ClipboardContent { + Self { data: NSData::with_bytes(data.as_bytes()), kind: NSStringPboardType.to_string(), } @@ -54,13 +54,13 @@ impl From for ClipboardContent { impl From<&str> for ClipboardContent { fn from(data: &str) -> Self { - ClipboardContent::from(data.to_string()) + Self::from(data.to_string()) } } impl From<&String> for ClipboardContent { fn from(data: &String) -> Self { - ClipboardContent::from(data.clone()) + Self::from(data.clone()) } } @@ -71,7 +71,7 @@ pub struct Clipboard { impl Clipboard { fn new() -> Self { unsafe { - Clipboard { + Self { pasteboard: Id::from_ptr(msg_send![class!(NSPasteboard), generalPasteboard]), } } @@ -121,6 +121,6 @@ impl Clipboard { impl Default for Clipboard { fn default() -> Self { - Clipboard::new() + Self::new() } } diff --git a/terramach/ui/platform/darwin/cursor.rs b/terramach/ui/platform/darwin/cursor.rs index 3068189..fbb88e7 100644 --- a/terramach/ui/platform/darwin/cursor.rs +++ b/terramach/ui/platform/darwin/cursor.rs @@ -27,7 +27,7 @@ pub enum Cursor { impl Default for Cursor { fn default() -> Self { - Cursor::Arrow + Self::Arrow } } @@ -36,7 +36,7 @@ pub struct Cursors {} impl Cursors { pub fn new() -> Self { - Cursors {} + Self {} } pub fn push(&mut self, cursor: impl Into>) { diff --git a/terramach/ui/platform/darwin/run_loop.rs b/terramach/ui/platform/darwin/run_loop.rs index 8324243..81e3ac9 100644 --- a/terramach/ui/platform/darwin/run_loop.rs +++ b/terramach/ui/platform/darwin/run_loop.rs @@ -34,11 +34,11 @@ const DISTANT_FUTURE_SECS: f64 = 1.0e10; pub struct RunLoopHandle(usize); impl Add for RunLoopHandle { - type Output = RunLoopHandle; + type Output = Self; fn add(self, rhs: usize) -> Self::Output { let (id, _) = self.0.overflowing_add(rhs); - RunLoopHandle(id) + Self(id) } } @@ -83,7 +83,7 @@ impl RunLoopObserver { run_loop_observer_callback, &mut context, ); - RunLoopObserver { + Self { inner: observer, callback, } @@ -122,7 +122,7 @@ impl RunLoopSource { perform: run_loop_source_callback, }; let source = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &mut context); - RunLoopSource { inner: source } + Self { inner: source } } } @@ -159,7 +159,7 @@ impl RunLoopTimer { run_loop_timer_callback, null_mut(), ); - RunLoopTimer { inner: timer } + Self { inner: timer } } } @@ -183,7 +183,7 @@ impl Clone for RunLoopTimer { fn clone(&self) -> Self { unsafe { CFRetain(self.inner as *const c_void); - RunLoopTimer { inner: self.inner } + Self { inner: self.inner } } } } @@ -198,7 +198,7 @@ impl SharedRunLoop { fn new(run_loop: &RunLoop) -> Self { unsafe { CFRetain(run_loop.inner as *const c_void); - SharedRunLoop { + Self { running: run_loop.running.clone(), run_loop: run_loop.inner, timer: run_loop.timer.clone(), @@ -229,7 +229,7 @@ impl Clone for SharedRunLoop { unsafe { CFRetain(self.run_loop as *const c_void); } - SharedRunLoop { + Self { running: self.running.clone(), run_loop: self.run_loop, timer: self.timer.clone(), @@ -257,11 +257,11 @@ pub struct RunLoop { impl RunLoop { pub fn main() -> Self { - unsafe { RunLoop::from_run_loop(CFRunLoopGetMain()) } + unsafe { Self::from_run_loop(CFRunLoopGetMain()) } } pub fn new() -> Self { - unsafe { RunLoop::from_run_loop(CFRunLoopGetCurrent()) } + unsafe { Self::from_run_loop(CFRunLoopGetCurrent()) } } fn from_run_loop(run_loop: CFRunLoopRef) -> Self { @@ -269,7 +269,7 @@ impl RunLoop { CFRetain(run_loop as *const c_void); let timer = RunLoopTimer::new(); CFRunLoopAddTimer(run_loop, timer.inner, kCFRunLoopCommonModes); - RunLoop { + Self { inner: run_loop, running: Rc::new(AtomicBool::new(false)), last_handle: RunLoopHandle::default(), diff --git a/terramach/ui/platform/glfw.rs b/terramach/ui/platform/glfw.rs index 4de28e8..a158d99 100644 --- a/terramach/ui/platform/glfw.rs +++ b/terramach/ui/platform/glfw.rs @@ -34,7 +34,7 @@ pub struct App { impl App { pub fn new() -> Self { - App { + Self { title: None, size: None, } diff --git a/terramach/ui/timers.rs b/terramach/ui/timers.rs index 0984d13..51f2721 100644 --- a/terramach/ui/timers.rs +++ b/terramach/ui/timers.rs @@ -28,7 +28,7 @@ pub struct Timer { impl Timer { pub fn new(delay: impl Into>, interval: impl Into>) -> Self { - Timer { + Self { delay: delay.into(), interval: interval.into(), } @@ -96,7 +96,7 @@ impl ScheduledTimer { impl From for ScheduledTimer { fn from(timer: Timer) -> Self { - ScheduledTimer { + Self { timer, timestamp: Instant::now(), ongoing: false, @@ -111,7 +111,7 @@ pub struct Timers { impl Timers { pub fn new() -> Self { - Timers { + Self { ids: IndexPool::new(), timers: HashMap::new(), } diff --git a/terramach/ui/touch.rs b/terramach/ui/touch.rs index 73531d8..9f1c617 100644 --- a/terramach/ui/touch.rs +++ b/terramach/ui/touch.rs @@ -30,7 +30,7 @@ pub struct Touch { impl Touch { pub fn new(id: TouchId, location: impl Into) -> Self { - Touch { + Self { id, location: location.into(), } @@ -52,7 +52,7 @@ pub struct Touches { impl Touches { pub fn new() -> Self { - Touches { + Self { touches: HashMap::new(), } } @@ -99,7 +99,7 @@ pub struct TouchTracker { impl TouchTracker { pub fn new() -> Self { - TouchTracker { + Self { touches: HashMap::new(), current: None, offset: None, diff --git a/terramach/ui/tree.rs b/terramach/ui/tree.rs index a15a65c..f403fe2 100644 --- a/terramach/ui/tree.rs +++ b/terramach/ui/tree.rs @@ -54,7 +54,7 @@ impl RenderTree { let root_widget = tree.insert(root, None); let mut need_build = HashSet::new(); need_build.insert(root_widget); - RenderTree { + Self { root_widget, tree, need_build, @@ -493,7 +493,7 @@ pub struct WidgetTexture { impl WidgetTexture { fn new(pipeline: &SharedPipeline, texture: TextureId) -> Self { - WidgetTexture { + Self { pipeline: pipeline.clone(), texture, } @@ -527,7 +527,7 @@ impl<'a> MountContext<'a> { texture_ids: &'a mut IndexPool, pipeline: &'a mut SharedPipeline, ) -> Self { - MountContext { + Self { id, texture_ids, tree, @@ -570,7 +570,7 @@ pub struct UpdateContext<'a> { impl<'a> UpdateContext<'a> { pub fn new(id: Id, tree: &'a Tree) -> Self { - UpdateContext { id, tree } + Self { id, tree } } pub fn ancestor_widget(&self) -> Option<&T> { @@ -599,7 +599,7 @@ pub struct BuildContext { impl BuildContext { pub fn new(event_emitter: WidgetEventEmitter) -> Self { - BuildContext { + Self { children: Vec::new(), event_emitter, } diff --git a/terramach/ui/widget.rs b/terramach/ui/widget.rs index b783af0..8e0ec8b 100644 --- a/terramach/ui/widget.rs +++ b/terramach/ui/widget.rs @@ -111,7 +111,7 @@ pub struct WidgetContext { impl WidgetContext { pub fn new() -> Self { - WidgetContext { + Self { state: None, frame_requested: false, timers: None, @@ -317,7 +317,7 @@ pub struct Channel { impl Channel { pub fn new() -> Self { - Channel { + Self { inner: Rc::new(RefCell::new(ChannelInner { active: true, send: None, diff --git a/terramach/ui/widgets/align.rs b/terramach/ui/widgets/align.rs index f0e3516..2554f59 100644 --- a/terramach/ui/widgets/align.rs +++ b/terramach/ui/widgets/align.rs @@ -34,7 +34,7 @@ pub enum MainAxisAlignment { impl Default for MainAxisAlignment { fn default() -> Self { - MainAxisAlignment::Start + Self::Start } } @@ -48,7 +48,7 @@ pub enum CrossAxisAlignment { impl Default for CrossAxisAlignment { fn default() -> Self { - CrossAxisAlignment::Start + Self::Start } } @@ -60,46 +60,46 @@ pub struct Alignment { impl Alignment { pub fn new(horizontal: impl Into>, vertical: impl Into>) -> Self { - Alignment { + Self { horizontal: horizontal.into().unwrap_or_default(), vertical: vertical.into().unwrap_or_default(), } } pub fn top_left() -> Self { - Alignment::new(-1.0, -1.0) + Self::new(-1.0, -1.0) } pub fn top_right() -> Self { - Alignment::new(1.0, -1.0) + Self::new(1.0, -1.0) } pub fn bottom_left() -> Self { - Alignment::new(1.0, -1.0) + Self::new(1.0, -1.0) } pub fn bottom_right() -> Self { - Alignment::new(1.0, 1.0) + Self::new(1.0, 1.0) } pub fn center() -> Self { - Alignment::new(None, None) + Self::new(None, None) } pub fn top_center() -> Self { - Alignment::new(None, -1.0) + Self::new(None, -1.0) } pub fn bottom_center() -> Self { - Alignment::new(None, 1.0) + Self::new(None, 1.0) } pub fn left_center() -> Self { - Alignment::new(-1.0, None) + Self::new(-1.0, None) } pub fn right_center() -> Self { - Alignment::new(1.0, None) + Self::new(1.0, None) } pub fn horizontal(&self) -> f32 { @@ -129,13 +129,13 @@ impl Hash for Alignment { impl Default for Alignment { fn default() -> Self { - Alignment::center() + Self::center() } } impl From<(f32, f32)> for Alignment { fn from(values: (f32, f32)) -> Self { - Alignment::new(values.0, values.1) + Self::new(values.0, values.1) } } @@ -147,7 +147,7 @@ pub struct Align { impl Align { pub fn new(alignment: impl Into>, child: impl Into) -> Self { - Align { + Self { alignment: alignment.into().unwrap_or_default(), child: child.into(), } diff --git a/terramach/ui/widgets/animated_opacity.rs b/terramach/ui/widgets/animated_opacity.rs index 7f9a45a..a5473a4 100644 --- a/terramach/ui/widgets/animated_opacity.rs +++ b/terramach/ui/widgets/animated_opacity.rs @@ -33,7 +33,7 @@ impl AnimatedOpacity { duration: impl Into>, child: impl Into, ) -> Self { - AnimatedOpacity { + Self { opacity: opacity.into().unwrap_or(1.0), duration: duration.into().unwrap_or(Duration::from_millis(350)), child: child.into(), @@ -94,7 +94,7 @@ struct AnimatedOpacityState { impl AnimatedOpacityState { pub fn new(opacity: f32) -> Self { - AnimatedOpacityState { + Self { opacity, animation: None, } diff --git a/terramach/ui/widgets/aspect_ratio.rs b/terramach/ui/widgets/aspect_ratio.rs index 5e6a050..9dae579 100644 --- a/terramach/ui/widgets/aspect_ratio.rs +++ b/terramach/ui/widgets/aspect_ratio.rs @@ -31,14 +31,14 @@ pub struct AspectRatio { impl AspectRatio { pub fn new(ratio: impl Into, child: impl Into) -> Self { - AspectRatio { + Self { ratio: ratio.into(), child: Some(child.into()), } } pub fn new_empty(ratio: impl Into) -> Self { - AspectRatio { + Self { ratio: ratio.into(), child: None, } diff --git a/terramach/ui/widgets/column.rs b/terramach/ui/widgets/column.rs index 26fc80e..d960b70 100644 --- a/terramach/ui/widgets/column.rs +++ b/terramach/ui/widgets/column.rs @@ -32,7 +32,7 @@ pub(crate) struct Flex { impl Flex { pub fn new(widget: impl Into, weight: impl Into>) -> Self { - Flex { + Self { widget: widget.into(), weight: weight.into(), } @@ -56,7 +56,7 @@ pub struct Column { impl Default for Column { fn default() -> Self { - Column::new(CrossAxisAlignment::Middle, None) + Self::new(CrossAxisAlignment::Middle, None) } } @@ -65,7 +65,7 @@ impl Column { horizontal_alignment: impl Into>, vertical_alignment: impl Into>, ) -> Self { - Column { + Self { children: Vec::new(), horizontal_alignment: horizontal_alignment.into(), vertical_alignment: vertical_alignment.into(), diff --git a/terramach/ui/widgets/constrained.rs b/terramach/ui/widgets/constrained.rs index 6ca6152..269d090 100644 --- a/terramach/ui/widgets/constrained.rs +++ b/terramach/ui/widgets/constrained.rs @@ -31,14 +31,14 @@ pub struct Constrained { impl Constrained { pub fn new_empty(constraints: impl Into) -> Self { - Constrained { + Self { constraints: constraints.into(), child: None, } } pub fn new(constraints: impl Into, child: impl Into) -> Self { - Constrained { + Self { constraints: constraints.into(), child: Some(child.into()), } diff --git a/terramach/ui/widgets/decoration.rs b/terramach/ui/widgets/decoration.rs index aeac6ff..1aedd08 100644 --- a/terramach/ui/widgets/decoration.rs +++ b/terramach/ui/widgets/decoration.rs @@ -40,7 +40,7 @@ impl BorderRadius { bottom_left: impl Into>, bottom_right: impl Into>, ) -> Self { - BorderRadius { + Self { top_left: top_left.into(), top_right: top_right.into(), bottom_left: bottom_left.into(), @@ -50,7 +50,7 @@ impl BorderRadius { pub fn new_all(radius: impl Into>) -> Self { let radius = radius.into().map(|r| Point::new(r, r)); - BorderRadius { + Self { top_left: radius, top_right: radius, bottom_left: radius, @@ -117,7 +117,7 @@ impl Decoration { background_color: impl Into>, border_radius: impl Into>, ) -> Self { - Decoration { + Self { background_color: background_color.into(), border_radius: border_radius.into(), child: None, @@ -129,7 +129,7 @@ impl Decoration { border_radius: impl Into>, child: impl Into, ) -> Self { - Decoration { + Self { background_color: background_color.into(), border_radius: border_radius.into(), child: Some(child.into()), diff --git a/terramach/ui/widgets/fractional.rs b/terramach/ui/widgets/fractional.rs index d59cee1..ee18178 100644 --- a/terramach/ui/widgets/fractional.rs +++ b/terramach/ui/widgets/fractional.rs @@ -31,14 +31,14 @@ pub struct Fractional { impl Fractional { pub fn new_empty(fraction: impl Into) -> Self { - Fractional { + Self { fraction: fraction.into(), child: None, } } pub fn new(fraction: impl Into, child: impl Into) -> Self { - Fractional { + Self { fraction: fraction.into(), child: Some(child.into()), } diff --git a/terramach/ui/widgets/gesture.rs b/terramach/ui/widgets/gesture.rs index a1a86e9..96bb0ff 100644 --- a/terramach/ui/widgets/gesture.rs +++ b/terramach/ui/widgets/gesture.rs @@ -39,7 +39,7 @@ impl Gesture { pan: impl Into>, child: impl Into, ) -> Self { - Gesture { + Self { event_id: event_id.into(), event_emitter, tap: tap.into(), @@ -112,7 +112,7 @@ impl GestureState { tap: Option, pan: Option, ) -> Self { - GestureState { + Self { event_id, event_emitter, tap, diff --git a/terramach/ui/widgets/image.rs b/terramach/ui/widgets/image.rs index e98b802..aeb031b 100644 --- a/terramach/ui/widgets/image.rs +++ b/terramach/ui/widgets/image.rs @@ -54,7 +54,7 @@ impl Image { bitmap.notify_pixels_changed(); let image = GrImage::from_bitmap(&bitmap).unwrap(); - Image { + Self { alignment: alignment.into().unwrap_or_default(), fit: fit.into().unwrap_or_default(), color: color.into(), diff --git a/terramach/ui/widgets/padding.rs b/terramach/ui/widgets/padding.rs index 950db1e..9a643b3 100644 --- a/terramach/ui/widgets/padding.rs +++ b/terramach/ui/widgets/padding.rs @@ -39,7 +39,7 @@ impl Padding { right: impl Into>, bottom: impl Into>, ) -> Self { - Padding { + Self { left: left.into().unwrap_or_default(), top: top.into().unwrap_or_default(), right: right.into().unwrap_or_default(), @@ -55,7 +55,7 @@ impl Padding { bottom: impl Into>, child: impl Into, ) -> Self { - Padding { + Self { left: left.into().unwrap_or_default(), top: top.into().unwrap_or_default(), right: right.into().unwrap_or_default(), @@ -66,17 +66,17 @@ impl Padding { pub fn new_all(padding: impl Into>, child: impl Into) -> Self { let padding = padding.into(); - Padding::new(padding, padding, padding, padding, child) + Self::new(padding, padding, padding, padding, child) } pub fn new_horizontal(padding: impl Into>, child: impl Into) -> Self { let padding = padding.into(); - Padding::new(padding, None, padding, None, child) + Self::new(padding, None, padding, None, child) } pub fn new_vertical(padding: impl Into>, child: impl Into) -> Self { let padding = padding.into(); - Padding::new(None, padding, None, padding, child) + Self::new(None, padding, None, padding, child) } } diff --git a/terramach/ui/widgets/row.rs b/terramach/ui/widgets/row.rs index df7600a..e75408a 100644 --- a/terramach/ui/widgets/row.rs +++ b/terramach/ui/widgets/row.rs @@ -33,7 +33,7 @@ pub struct Row { impl Default for Row { fn default() -> Self { - Row::new(None, CrossAxisAlignment::Middle) + Self::new(None, CrossAxisAlignment::Middle) } } @@ -42,7 +42,7 @@ impl Row { horizontal_alignment: impl Into>, vertical_alignment: impl Into>, ) -> Self { - Row { + Self { children: Vec::new(), horizontal_alignment: horizontal_alignment.into(), vertical_alignment: vertical_alignment.into(), diff --git a/terramach/ui/widgets/scrollable.rs b/terramach/ui/widgets/scrollable.rs index d6ef13f..91ffb91 100644 --- a/terramach/ui/widgets/scrollable.rs +++ b/terramach/ui/widgets/scrollable.rs @@ -34,7 +34,7 @@ pub enum ScrollDirection { impl Default for ScrollDirection { fn default() -> Self { - ScrollDirection::Vertical + Self::Vertical } } @@ -54,7 +54,7 @@ impl Scrollable { const SCROLLBAR_DEACTIVATE: usize = 1; pub fn new(direction: ScrollDirection, child: impl Into) -> Self { - Scrollable { + Self { direction, child: child.into(), } @@ -248,7 +248,7 @@ struct ScrollableState { impl ScrollableState { pub fn new() -> Self { - ScrollableState { + Self { size: None, content_size: None, location: Point::default(), diff --git a/terramach/ui/widgets/stack.rs b/terramach/ui/widgets/stack.rs index f363d11..f242eff 100644 --- a/terramach/ui/widgets/stack.rs +++ b/terramach/ui/widgets/stack.rs @@ -28,7 +28,7 @@ pub struct Stack { impl Stack { pub fn new() -> Self { - Stack { + Self { children: Vec::new(), } } diff --git a/terramach/ui/widgets/text.rs b/terramach/ui/widgets/text.rs index ce99efa..24c69dc 100644 --- a/terramach/ui/widgets/text.rs +++ b/terramach/ui/widgets/text.rs @@ -264,7 +264,7 @@ impl Text { text: impl Into>, text_style: impl Into>, ) -> Self { - Text { + Self { text: text.into().map(|s| s.as_ref().to_string()).unwrap_or_default(), text_style: text_style.into(), } diff --git a/terramach/ui/widgets/text_input.rs b/terramach/ui/widgets/text_input.rs index 0afc260..88a8b47 100644 --- a/terramach/ui/widgets/text_input.rs +++ b/terramach/ui/widgets/text_input.rs @@ -55,7 +55,7 @@ impl TextInput { hint: impl Into>, max_lines: impl Into>, ) -> Self { - TextInput { + Self { text: text.into().map(|s| s.as_ref().to_string()).unwrap_or_default(), text_style: text_style.into(), text_align: text_align.into().unwrap_or(TextAlign::Start), @@ -65,7 +65,7 @@ impl TextInput { } pub fn new_empty() -> Self { - TextInput { + Self { text: String::default(), text_style: None, text_align: TextAlign::Start, @@ -406,7 +406,7 @@ struct TextSelection { impl TextSelection { pub fn new(text: impl AsRef) -> Self { - TextSelection { + Self { text: text.as_ref().to_string(), begin: 0, end: 0, @@ -694,7 +694,7 @@ impl TextState { hint_color: Color, selection_color: Color, ) -> Self { - TextState { + Self { font_collection, paragraph_style, text_style, diff --git a/third-party/mapbox/build_support/mapbox.rs b/third-party/mapbox/build_support/mapbox.rs index 2dad7a1..d1645b5 100644 --- a/third-party/mapbox/build_support/mapbox.rs +++ b/third-party/mapbox/build_support/mapbox.rs @@ -37,7 +37,7 @@ impl BuildConfiguration { source_dir: impl AsRef, build_dir: impl AsRef, ) -> Self { - BuildConfiguration { + Self { source_dir: source_dir.as_ref().to_path_buf(), build_dir: build_dir.as_ref().to_path_buf(), } diff --git a/third-party/mapbox/src/frontend.rs b/third-party/mapbox/src/frontend.rs index 3afad79..1fc3b8d 100644 --- a/third-party/mapbox/src/frontend.rs +++ b/third-party/mapbox/src/frontend.rs @@ -50,7 +50,7 @@ impl RendererFrontend { pixel_ratio, invalidate: Box::new(invalidate), })); - RendererFrontend { + Self { pixel_ratio, handle: Handle::from_ptr(bindings::C_RendererFrontend_new( backend.into_handle().into_ptr(), diff --git a/third-party/mapbox/src/map.rs b/third-party/mapbox/src/map.rs index 5d286b4..0905d34 100644 --- a/third-party/mapbox/src/map.rs +++ b/third-party/mapbox/src/map.rs @@ -38,7 +38,7 @@ pub struct MapOptions { impl MapOptions { pub fn new() -> Self { unsafe { - MapOptions { + Self { handle: Handle::new_native(bindings::mbgl_MapOptions_MapOptions) } } @@ -61,7 +61,7 @@ impl MapOptions { impl Default for MapOptions { fn default() -> Self { - MapOptions::new() + Self::new() } } @@ -94,7 +94,7 @@ impl Map { resource_options: &ResourceOptions, ) -> Self { unsafe { - Map { + Self { handle: Handle::from_ptr(bindings::C_Map_new( Scheduler::new().into_handle().into_ptr(), frontend.into_handle().into_ptr(), diff --git a/third-party/mapbox/src/native.rs b/third-party/mapbox/src/native.rs index 736bf66..6c47f0e 100644 --- a/third-party/mapbox/src/native.rs +++ b/third-party/mapbox/src/native.rs @@ -30,14 +30,14 @@ impl Handle { } pub unsafe fn new_native(f: unsafe extern "C" fn(*mut T)) -> Self { - Handle::new(|this| f(this)) + Self::new(|this| f(this)) } pub fn new(f: F) -> Self where F: FnOnce(*mut T) { let mut instance = std::mem::MaybeUninit::uninit(); f(instance.as_mut_ptr()); unsafe { - Handle::from_ptr(Box::into_raw(Box::new(instance.assume_init()))) + Self::from_ptr(Box::into_raw(Box::new(instance.assume_init()))) } } } @@ -74,7 +74,7 @@ pub trait NativeCopy { impl Clone for Handle where T: NativeDrop + NativeCopy { fn clone(&self) -> Self { - Handle::new(|this| self.native().copy_to(this)) + Self::new(|this| self.native().copy_to(this)) } } diff --git a/third-party/mapbox/src/prelude.rs b/third-party/mapbox/src/prelude.rs index 61cc090..ba3c99e 100644 --- a/third-party/mapbox/src/prelude.rs +++ b/third-party/mapbox/src/prelude.rs @@ -28,7 +28,7 @@ pub type Size = bindings::mbgl_Size; impl Size { pub fn new(width: u32, height: u32) -> Self { - Size { + Self { width, height, } @@ -37,7 +37,7 @@ impl Size { impl From<(u32, u32)> for Size { fn from(size: (u32, u32)) -> Self { - Size::new(size.0, size.1) + Self::new(size.0, size.1) } } @@ -56,7 +56,7 @@ pub struct ResourceOptions { impl ResourceOptions { pub fn new() -> Self { unsafe { - ResourceOptions { + Self { handle: Handle::new_native(bindings::mbgl_ResourceOptions_ResourceOptions), } } @@ -82,7 +82,7 @@ impl ResourceOptions { impl Default for ResourceOptions { fn default() -> Self { - ResourceOptions::new() + Self::new() } } @@ -101,7 +101,7 @@ pub struct LatLng(bindings::mbgl_LatLng); impl LatLng { pub fn new(latitude: f64, longitude: f64) -> Self { - LatLng(bindings::mbgl_LatLng { + Self(bindings::mbgl_LatLng { lat: latitude, lon: longitude, }) @@ -114,13 +114,13 @@ impl LatLng { impl Default for LatLng { fn default() -> Self { - LatLng::new(0.0, 0.0) + Self::new(0.0, 0.0) } } impl From<(f64, f64)> for LatLng { fn from(values: (f64, f64)) -> Self { - LatLng::new(values.0, values.1) + Self::new(values.0, values.1) } } @@ -165,7 +165,7 @@ pub struct CameraOptions { impl CameraOptions { pub fn new() -> Self { unsafe { - CameraOptions { + Self { handle: Handle::from_ptr(bindings::C_CameraOptions_new()), } } @@ -204,7 +204,7 @@ impl NativeAccess for CameraOptions { impl Default for CameraOptions { fn default() -> Self { - CameraOptions::new() + Self::new() } } @@ -252,14 +252,14 @@ impl NativeAccess for AnimationOptions { impl Default for AnimationOptions { fn default() -> Self { - AnimationOptions::new() + Self::new() } } impl AnimationOptions { pub fn new() -> Self { unsafe { - AnimationOptions { + Self { handle: Handle::from_ptr(bindings::C_AnimationOptions_new()), } } @@ -281,7 +281,7 @@ pub struct ScreenCoordinate(bindings::mbgl_ScreenCoordinate); impl ScreenCoordinate { pub fn new(x: f32, y: f32) -> Self { - ScreenCoordinate(bindings::mbgl_ScreenCoordinate { + Self(bindings::mbgl_ScreenCoordinate { x: x as f64, y: y as f64, _phantom_0: PhantomData, @@ -295,13 +295,13 @@ impl ScreenCoordinate { impl Default for ScreenCoordinate { fn default() -> Self { - ScreenCoordinate::new(0.0, 0.0) + Self::new(0.0, 0.0) } } impl From<(f32, f32)> for ScreenCoordinate { fn from(values: (f32, f32)) -> Self { - ScreenCoordinate::new(values.0, values.1) + Self::new(values.0, values.1) } } diff --git a/third-party/mapbox/src/scheduler.rs b/third-party/mapbox/src/scheduler.rs index 0d8698b..6f5291a 100644 --- a/third-party/mapbox/src/scheduler.rs +++ b/third-party/mapbox/src/scheduler.rs @@ -44,7 +44,7 @@ pub struct Scheduler { impl Scheduler { pub fn new() -> Self { unsafe { - Scheduler { + Self { handle: Handle::from_ptr(bindings::C_Scheduler_new()), } }