diff --git a/alchemy/src/app.rs b/alchemy/src/app.rs index f1230d2..c5a30f8 100644 --- a/alchemy/src/app.rs +++ b/alchemy/src/app.rs @@ -1,5 +1,5 @@ -//! This module implements the Application structure and associated -//! lifecycle methods. You typically never create this struct yourself; +//! This module implements the Application structure and associated +//! lifecycle methods. You typically never create this struct yourself; //! in Alchemy, there's a global `shared_app` that you should use to work //! with the `App` struct. //! @@ -28,7 +28,7 @@ impl AppDelegate for DefaultAppDelegate {} /// also stored here for easy access. pub struct App { pub(crate) bridge: Mutex>, - pub delegate: Mutex>, + pub delegate: Mutex>, pub windows: WindowManager } @@ -54,7 +54,7 @@ impl App { *bridge = Some(PlatformAppBridge::new(ptr)); } - /// Convenience method for registering one-off styles. Typically, you would want + /// Convenience method for registering one-off styles. Typically, you would want /// to store your stylesheets as separate files, to enable hot-reloading - but it's /// conceivable that you might want to just have them in your app, too, and this enables /// that use case. @@ -88,35 +88,35 @@ impl AppDelegate for App { let mut delegate = self.delegate.lock().unwrap(); delegate.will_finish_launching(); } - + /// Called when the application did finish launching. - fn did_finish_launching(&mut self) { + fn did_finish_launching(&mut self) { let mut delegate = self.delegate.lock().unwrap(); delegate.did_finish_launching(); } - /// Called when the application will become active. We can use this, for instance, - /// to resume rendering cycles and so on. + /// Called when the application will become active. We can use this, for instance, + /// to resume rendering cycles and so on. fn will_become_active(&mut self) { let mut delegate = self.delegate.lock().unwrap(); delegate.will_become_active(); } - /// Called when the application did become active. We can use this, for instance, + /// Called when the application did become active. We can use this, for instance, /// to resume rendering cycles and so on. fn did_become_active(&mut self) { let mut delegate = self.delegate.lock().unwrap(); delegate.did_become_active(); } - /// Called when the application will resigned active. We can use this, for instance, + /// Called when the application will resigned active. We can use this, for instance, /// to pause rendering cycles and so on. fn will_resign_active(&mut self) { let mut delegate = self.delegate.lock().unwrap(); delegate.will_resign_active(); } - /// Called when the application has resigned active. We can use this, for instance, + /// Called when the application has resigned active. We can use this, for instance, /// to pause rendering cycles and so on. fn did_resign_active(&mut self) { let mut delegate = self.delegate.lock().unwrap(); diff --git a/alchemy/src/components/fragment.rs b/alchemy/src/components/fragment.rs index a3c940e..a598673 100644 --- a/alchemy/src/components/fragment.rs +++ b/alchemy/src/components/fragment.rs @@ -1,7 +1,7 @@ //! A Fragment is for components that want to return or hoist multiple inner //! child nodes. `impl IntoIterator` can't be used in trait returns right now, //! and this API more or less matches what React presents, so I'm fine with it... -//! but as the language stabilizes even further I'd love to get rid of this and +//! but as the language stabilizes even further I'd love to get rid of this and //! just allow returning arbitrary iterators. use alchemy_lifecycle::ComponentKey; @@ -12,7 +12,7 @@ pub struct FragmentProps; /// Fragments are special - you can do something like the following in cases where you /// want to render some views without requiring an intermediate view. /// -/// ``` +/// ```ignore /// /// /// @@ -29,7 +29,7 @@ impl Fragment { } impl Props for Fragment { - fn set_props(&mut self, _: &mut std::any::Any) {} + fn set_props(&mut self, _: &mut dyn std::any::Any) {} } impl Component for Fragment { diff --git a/alchemy/src/components/text.rs b/alchemy/src/components/text.rs index 105a537..ddf59c3 100644 --- a/alchemy/src/components/text.rs +++ b/alchemy/src/components/text.rs @@ -1,6 +1,6 @@ //! Handles hoisting per-platform specific Text components. //! Each platform needs the freedom to do some specific things, -//! hence why they're all (somewhat annoyingly, but lovingly) re-implemented +//! hence why they're all (somewhat annoyingly, but lovingly) re-implemented //! as bridges. use std::sync::{Mutex}; @@ -22,7 +22,7 @@ pub struct TextProps; /// /// Views accept styles and event callbacks as props. For example: /// -/// ``` +/// ```ignore /// /// ``` pub struct Text(Mutex); @@ -38,7 +38,7 @@ impl Text { } impl Props for Text { - fn set_props(&mut self, _: &mut std::any::Any) {} + fn set_props(&mut self, _: &mut dyn std::any::Any) {} } impl Component for Text { @@ -47,7 +47,7 @@ impl Component for Text { } fn has_native_backing_node(&self) -> bool { true } - + fn borrow_native_backing_node(&self) -> Option { let bridge = self.0.lock().unwrap(); Some(bridge.borrow_native_backing_node()) @@ -75,10 +75,10 @@ impl Component for Text { RSX::VirtualText(s) => s.0.to_owned(), _ => String::new() }).collect::(); - + let mut bridge = self.0.lock().unwrap(); bridge.set_text(text); - + Ok(RSX::None) } } diff --git a/alchemy/src/components/view.rs b/alchemy/src/components/view.rs index a8ccdaf..affbe6a 100644 --- a/alchemy/src/components/view.rs +++ b/alchemy/src/components/view.rs @@ -1,6 +1,6 @@ //! Handles hoisting per-platform specific View components. //! Each platform needs the freedom to do some specific things, -//! hence why they're all (somewhat annoyingly, but lovingly) re-implemented +//! hence why they're all (somewhat annoyingly, but lovingly) re-implemented //! as bridges. use std::sync::Mutex; @@ -24,7 +24,7 @@ pub struct ViewProps; /// /// Views accept styles and event callbacks as props. For example: /// -/// ``` +/// ```ignore /// /// ``` pub struct View { @@ -46,7 +46,7 @@ impl View { } impl Props for View { - fn set_props(&mut self, _: &mut std::any::Any) {} + fn set_props(&mut self, _: &mut dyn std::any::Any) {} } impl Component for View { @@ -55,7 +55,7 @@ impl Component for View { } fn has_native_backing_node(&self) -> bool { true } - + fn borrow_native_backing_node(&self) -> Option { let bridge = self.bridge.lock().unwrap(); Some(bridge.borrow_native_backing_node()) diff --git a/alchemy/src/window/manager.rs b/alchemy/src/window/manager.rs index 630c6e0..8b52c50 100644 --- a/alchemy/src/window/manager.rs +++ b/alchemy/src/window/manager.rs @@ -7,7 +7,7 @@ //! right? //! //! There's also the fact that a user could opt to close a window. If that happens, we want to be -//! able to remove it from our structure... hence this manager that acts as a lightweight interface +//! able to remove it from our structure... hence this manager that acts as a lightweight interface //! for managing per-platform Window instances. use std::sync::{Arc, Mutex}; @@ -32,7 +32,7 @@ impl WindowManager { /// Adds an `AppWindow` to this instance. pub(crate) fn add(&self, window: Arc>) { let mut windows = self.0.lock().unwrap(); - if let None = windows.iter().position(|w| Arc::ptr_eq(&w, &window)) { + if windows.iter().position(|w| Arc::ptr_eq(&w, &window)).is_none() { windows.push(window); } } @@ -46,7 +46,7 @@ impl WindowManager { let mut windows = self.0.lock().unwrap(); if let Some(index) = windows.iter().position(|window| { let mut w = window.lock().unwrap(); - + if w.id == window_id { w.delegate.will_close(); return true; diff --git a/alchemy/src/window/window.rs b/alchemy/src/window/window.rs index 9c4a84b..6841661 100644 --- a/alchemy/src/window/window.rs +++ b/alchemy/src/window/window.rs @@ -24,7 +24,7 @@ pub struct AppWindow { pub title: String, pub dimensions: (f64, f64, f64, f64), pub bridge: PlatformWindowBridge, - pub delegate: Box, + pub delegate: Box, pub render_key: ComponentKey } @@ -92,7 +92,7 @@ impl Window { let window_id = SHARED_APP.windows.allocate_new_window_id(); let view = View::default(); let shared_app_ptr: *const App = &**SHARED_APP; - + // This unwrap() is fine, since we implement View ourselves in Alchemy let backing_node = view.borrow_native_backing_node().unwrap(); let bridge = PlatformWindowBridge::new(window_id, backing_node, shared_app_ptr); @@ -101,13 +101,13 @@ impl Window { Ok(key) => key, Err(_e) => { panic!("Uhhhh this really messed up"); } }; - + Window(Arc::new(Mutex::new(AppWindow { id: window_id, style_keys: "".into(), title: "".into(), dimensions: (0., 0., 0., 0.), - bridge: bridge, + bridge, delegate: Box::new(delegate), render_key: key }))) @@ -147,7 +147,7 @@ impl Window { /// Closes the window, unregistering it from the window manager in the process and ensuring the /// necessary delegate method(s) are fired. pub fn close(&self) { - let window_id = self.0.lock().unwrap().id; + let window_id = self.0.lock().unwrap().id; SHARED_APP.windows.will_close(window_id); let mut window = self.0.lock().unwrap(); window.close(); diff --git a/clippy.toml b/clippy.toml index 9fa08ad..74c9364 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,4 +1,4 @@ -cyclomatic-complexity-threshold = 30 +cognitive-complexity-threshold = 30 doc-valid-idents = [ "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "OpenGL", "TrueType", diff --git a/cocoa/src/app.rs b/cocoa/src/app.rs index f2152ea..00945d7 100644 --- a/cocoa/src/app.rs +++ b/cocoa/src/app.rs @@ -1,7 +1,7 @@ //! A wrapper for `NSApplication` on macOS. If you opt in to the `cocoa` feature on //! Alchemy, this will loop system-level application events back to your `AppDelegate`. -use std::sync::{Once, ONCE_INIT}; +use std::sync::{Once}; use cocoa::base::{id, nil}; use cocoa::appkit::{NSApplication, NSRunningApplication}; @@ -15,7 +15,7 @@ use alchemy_lifecycle::traits::AppDelegate; static ALCHEMY_APP_PTR: &str = "alchemyParentAppPtr"; -/// A wrapper for `NSApplication`. It holds (retains) pointers for the Objective-C runtime, +/// A wrapper for `NSApplication`. It holds (retains) pointers for the Objective-C runtime, /// which is where our application instance lives. It also injects an `NSObject` subclass, /// which acts as the Delegate, looping back into our Alchemy shared application. pub struct App { @@ -34,7 +34,7 @@ impl App { app.setActivationPolicy_(cocoa::appkit::NSApplicationActivationPolicyRegular); Id::from_ptr(app) }; - + let delegate = unsafe { let delegate_class = register_app_delegate_class::(); let delegate: id = msg_send![delegate_class, new]; @@ -127,7 +127,7 @@ extern fn will_terminate(this: &Object, _: Sel, _: id) { /// pointers we need to have. fn register_app_delegate_class() -> *const Class { static mut DELEGATE_CLASS: *const Class = 0 as *const Class; - static INIT: Once = ONCE_INIT; + static INIT: Once = Once::new(); INIT.call_once(|| unsafe { let superclass = Class::get("NSObject").unwrap(); diff --git a/cocoa/src/text.rs b/cocoa/src/text.rs index 2845955..57af4ff 100644 --- a/cocoa/src/text.rs +++ b/cocoa/src/text.rs @@ -1,7 +1,7 @@ //! This wraps NTextField on macOS, and configures it to act like a label //! with standard behavior that most users would expect. -use std::sync::{Once, ONCE_INIT}; +use std::sync::{Once}; use objc_id::{Id, ShareId}; use objc::{msg_send, sel, sel_impl}; @@ -19,7 +19,7 @@ use alchemy_lifecycle::traits::PlatformSpecificNodeType; static ALCHEMY_DELEGATE: &str = "alchemyDelegate"; -/// A wrapper for `NSText`. This holds retained pointers for the Objective-C +/// A wrapper for `NSText`. This holds retained pointers for the Objective-C /// runtime - namely, the view itself, and associated things such as background /// colors and so forth. #[derive(Debug)] @@ -83,7 +83,7 @@ impl Text { self.background_color = appearance.background_color.into_nscolor(); self.text_color = appearance.text_color.into_nscolor(); - + msg_send![&*self.inner_mut, setFrame:rect]; msg_send![&*self.inner_mut, setBackgroundColor:&*self.background_color]; msg_send![&*self.inner_mut, setTextColor:&*self.text_color]; @@ -112,12 +112,12 @@ extern fn enforce_normalcy(_: &Object, _: Sel) -> BOOL { /// to store. fn register_class() -> *const Class { static mut VIEW_CLASS: *const Class = 0 as *const Class; - static INIT: Once = ONCE_INIT; + static INIT: Once = Once::new(); INIT.call_once(|| unsafe { let superclass = Class::get("NSTextField").unwrap(); let mut decl = ClassDecl::new("AlchemyTextField", superclass).unwrap(); - + // Force NSText to render from the top-left, not bottom-left //decl.add_method(sel!(isFlipped), enforce_normalcy as extern fn(&Object, _) -> BOOL); @@ -132,7 +132,7 @@ fn register_class() -> *const Class { // Note that NSText's don't really have a "delegate", I'm just using it here // for common terminology sake. decl.add_ivar::(ALCHEMY_DELEGATE); - + VIEW_CLASS = decl.register(); }); diff --git a/cocoa/src/view.rs b/cocoa/src/view.rs index 5b123cb..03b6d85 100644 --- a/cocoa/src/view.rs +++ b/cocoa/src/view.rs @@ -1,7 +1,7 @@ //! Implements a View Component struct. The most common //! basic building block of any app. Wraps NSView on macOS. -use std::sync::{Once, ONCE_INIT}; +use std::sync::{Once}; use objc_id::{Id, ShareId}; use objc::{msg_send, sel, sel_impl}; @@ -20,7 +20,7 @@ use alchemy_lifecycle::traits::PlatformSpecificNodeType; static ALCHEMY_DELEGATE: &str = "alchemyDelegate"; static BACKGROUND_COLOR: &str = "alchemyBackgroundColor"; -/// A wrapper for `NSView`. This holds retained pointers for the Objective-C +/// A wrapper for `NSView`. This holds retained pointers for the Objective-C /// runtime - namely, the view itself, and associated things such as background /// colors and so forth. #[derive(Debug)] @@ -76,8 +76,8 @@ impl View { ); self.background_color = appearance.background_color.into_nscolor(); - self.inner_mut.set_ivar(BACKGROUND_COLOR, &*self.background_color); - + self.inner_mut.set_ivar(BACKGROUND_COLOR, &*self.background_color); + msg_send![&*self.inner_mut, setFrame:rect]; msg_send![&*self.inner_mut, setNeedsDisplay:YES]; } @@ -107,12 +107,12 @@ extern fn update_layer(this: &Object, _: Sel) { /// to store. fn register_class() -> *const Class { static mut VIEW_CLASS: *const Class = 0 as *const Class; - static INIT: Once = ONCE_INIT; + static INIT: Once = Once::new(); INIT.call_once(|| unsafe { let superclass = Class::get("NSView").unwrap(); let mut decl = ClassDecl::new("AlchemyView", superclass).unwrap(); - + // Force NSView to render from the top-left, not bottom-left decl.add_method(sel!(isFlipped), enforce_normalcy as extern fn(&Object, _) -> BOOL); @@ -131,7 +131,7 @@ fn register_class() -> *const Class { // for common terminology sake. decl.add_ivar::(ALCHEMY_DELEGATE); decl.add_ivar::(BACKGROUND_COLOR); - + VIEW_CLASS = decl.register(); }); diff --git a/cocoa/src/window.rs b/cocoa/src/window.rs index 64b4dd9..959a108 100644 --- a/cocoa/src/window.rs +++ b/cocoa/src/window.rs @@ -2,7 +2,7 @@ //! Cocoa and associated widgets. This also handles looping back //! lifecycle events, such as window resizing or close events. -use std::sync::{Once, ONCE_INIT}; +use std::sync::{Once}; use cocoa::base::{id, nil, YES, NO}; use cocoa::appkit::{NSWindow, NSWindowStyleMask, NSBackingStoreType}; @@ -19,7 +19,7 @@ use alchemy_styles::Appearance; static APP_PTR: &str = "alchemyAppPtr"; static WINDOW_MANAGER_ID: &str = "alchemyWindowManagerID"; -/// A wrapper for `NSWindow`. Holds (retains) pointers for the Objective-C runtime +/// A wrapper for `NSWindow`. Holds (retains) pointers for the Objective-C runtime /// where our `NSWindow` and associated delegate live. pub struct Window { pub inner: ShareId, @@ -39,7 +39,7 @@ impl Window { let inner = unsafe { let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_( - dimensions, + dimensions, style, NSBackingStoreType::NSBackingStoreBuffered, NO @@ -52,14 +52,14 @@ impl Window { // to disable, like... this. If we don't set this, we'll segfault entirely because the // Objective-C runtime gets out of sync. msg_send![window, setReleasedWhenClosed:NO]; - + //if let Some(view_ptr) = content_view.borrow_native_backing_node() { msg_send![window, setContentView:content_view]; //} ShareId::from_ptr(window) }; - + let delegate = unsafe { let delegate_class = register_window_class::(); let delegate: id = msg_send![delegate_class, new]; @@ -128,7 +128,7 @@ impl Drop for Window { /// safer than sorry. fn drop(&mut self) { // This bridging link needs to be broken on Drop. - unsafe { + unsafe { msg_send![&*self.inner, setDelegate:nil]; } } @@ -149,7 +149,7 @@ extern fn will_close(this: &Object, _: Sel, _: id) { /// need to do. fn register_window_class() -> *const Class { static mut DELEGATE_CLASS: *const Class = 0 as *const Class; - static INIT: Once = ONCE_INIT; + static INIT: Once = Once::new(); INIT.call_once(|| unsafe { let superclass = Class::get("NSObject").unwrap(); @@ -157,9 +157,9 @@ fn register_window_class() -> *const Class { decl.add_ivar::(APP_PTR); decl.add_ivar::(WINDOW_MANAGER_ID); - + decl.add_method(sel!(windowWillClose:), will_close:: as extern fn(&Object, _, _)); - + DELEGATE_CLASS = decl.register(); }); diff --git a/lifecycle/src/error.rs b/lifecycle/src/error.rs index f9c1d35..7533f3d 100644 --- a/lifecycle/src/error.rs +++ b/lifecycle/src/error.rs @@ -4,4 +4,4 @@ /// A generic Error type that we use. It currently just aliases to `Box`, /// but could change in the future. -pub type Error = Box; +pub type Error = Box; diff --git a/lifecycle/src/reconciler/generic_root_view_stub.rs b/lifecycle/src/reconciler/generic_root_view_stub.rs index 4658c5f..1b86130 100644 --- a/lifecycle/src/reconciler/generic_root_view_stub.rs +++ b/lifecycle/src/reconciler/generic_root_view_stub.rs @@ -21,7 +21,7 @@ impl GenericRootView { } impl Props for GenericRootView { - fn set_props(&mut self, _: &mut Any) {} + fn set_props(&mut self, _: &mut dyn Any) {} } impl Component for GenericRootView { diff --git a/lifecycle/src/reconciler/mod.rs b/lifecycle/src/reconciler/mod.rs index 093b9dc..83eb71c 100644 --- a/lifecycle/src/reconciler/mod.rs +++ b/lifecycle/src/reconciler/mod.rs @@ -1,6 +1,6 @@ -//! Implements tree diffing, updating, and so on. Unlike a lot of the VDom implementations -//! you find littered around the web, this is a bit more ECS-ish, and expects Components to retain -//! their `ComponentKey` passed in their constructor if they want to update. Doing this +//! Implements tree diffing, updating, and so on. Unlike a lot of the VDom implementations +//! you find littered around the web, this is a bit more ECS-ish, and expects Components to retain +//! their `ComponentKey` passed in their constructor if they want to update. Doing this //! enables us to avoid re-scanning or diffing an entire tree. use std::sync::Mutex; @@ -48,12 +48,12 @@ impl RenderEngine { // pub fn queue_update_for(&self, component_ptr: usize, updater: Box Component + Send + Sync + 'static>) { // } - /// `Window`'s (or anything "root" in nature) need to register with the + /// `Window`'s (or anything "root" in nature) need to register with the /// reconciler for things like setState to work properly. When they do so, - /// they get a key back. When they want to instruct the global `RenderEngine` - /// to re-render or update their tree, they pass that key and whatever the new tree + /// they get a key back. When they want to instruct the global `RenderEngine` + /// to re-render or update their tree, they pass that key and whatever the new tree /// should be. - pub fn register_root_component(&self, component: C) -> Result> { + pub fn register_root_component(&self, component: C) -> Result> { // Conceivably, this doesn't NEED to be a thing... but for now it is. If you've stumbled // upon here, wayward traveler, in need of a non-native-root-component, please open an // issue to discuss. :) @@ -75,7 +75,7 @@ impl RenderEngine { Ok(component_key) } - /// Rendering the root node is a bit different than rendering or updating other nodes, as we + /// Rendering the root node is a bit different than rendering or updating other nodes, as we /// never want to unmount it, and the results come from a non-`Component` entity (e.g, a /// `Window`). Thus, for this one, we do some manual mucking with what we know is the /// root view (a `Window` or such root component would call this with it's registered @@ -85,7 +85,7 @@ impl RenderEngine { key: ComponentKey, dimensions: (f64, f64), child: RSX - ) -> Result<(), Box> { + ) -> Result<(), Box> { let mut component_store = self.components.lock().unwrap(); let mut layout_store = self.layouts.lock().unwrap(); @@ -122,7 +122,7 @@ impl RenderEngine { width: Number::Defined(dimensions.0 as f32), height: Number::Defined(dimensions.1 as f32) })?; - + walk_and_apply_styles(key, &mut component_store, &mut layout_store)?; Ok(()) @@ -138,8 +138,8 @@ fn recursively_diff_tree( new_tree: RSX, component_store: &mut ComponentStore, layout_store: &mut LayoutStore -) -> Result<(), Box> { - // First we need to determine if this node is being replaced or updated. A replace happens if +) -> Result<(), Box> { + // First we need to determine if this node is being replaced or updated. A replace happens if // two nodes are different types - in this case, we check their tag values. This is also a case // where, for instance, if the RSX tag is `::None` or `::VirtualText`, we'll treat it as // replacing with nothing. @@ -173,7 +173,7 @@ fn recursively_diff_tree( if let RSX::VirtualNode(mut child) = new_tree { for new_child_tree in child.children { match old_children.pop() { - // If there's a key in the old children for this position, it's + // If there's a key in the old children for this position, it's // something we need to update, so let's recurse right back into it. Some(old_child_key) => { recursively_diff_tree( @@ -184,7 +184,7 @@ fn recursively_diff_tree( )?; }, - // If there's no matching old key in this position, then we've got a + // If there's no matching old key in this position, then we've got a // new component instance to mount. This part now diverts into the Mount // phase. None => { @@ -218,17 +218,17 @@ fn recursively_diff_tree( /// tree, emitting required lifecycle events and persisting values. This happens in an inward-out /// fashion, which helps avoid unnecessary reflow in environments where it can get tricky. /// -/// This method returns a Result, the `Ok` variant containing a tuple of Vecs. These are the child +/// This method returns a Result, the `Ok` variant containing a tuple of Vecs. These are the child /// Component instances and Layout instances that need to be set in the stores. fn mount_component_tree( tree: VirtualNode, component_store: &mut ComponentStore, layout_store: &mut LayoutStore -) -> Result> { +) -> Result> { let key = component_store.new_key(); let component = (tree.create_component_fn)(key); let is_native_backed = component.has_native_backing_node(); - + // let state = get_derived_state_from_props() let mut instance = Instance { tag: tree.tag, @@ -243,7 +243,7 @@ fn mount_component_tree( THEME_ENGINE.configure_styles_for_keys(&instance.style_keys, &mut style, &mut instance.appearance); instance.layout = Some(layout_store.new_node(style, vec![])?); } - + let rendered = instance.component.render(tree.children); // instance.get_snapshot_before_update() component_store.insert(key, instance)?; @@ -258,7 +258,7 @@ fn mount_component_tree( for child_tree in child.children { if let RSX::VirtualNode(child_tree) = child_tree { let child_key = mount_component_tree(child_tree, component_store, layout_store)?; - + component_store.add_child(key, child_key)?; if is_native_backed { link_layout_nodess(key, child_key, component_store, layout_store)?; @@ -267,7 +267,7 @@ fn mount_component_tree( } } else { let child_key = mount_component_tree(child, component_store, layout_store)?; - + component_store.add_child(key, child_key)?; if is_native_backed { link_layout_nodess(key, child_key, component_store, layout_store)?; @@ -298,12 +298,12 @@ fn unmount_component_tree( key: ComponentKey, component_store: &mut ComponentStore, layout_store: &mut LayoutStore -) -> Result, Box> { +) -> Result, Box> { let mut instance = component_store.remove(key)?; instance.component.component_will_unmount(); - + let mut layout_nodes = vec![]; - + let children = component_store.children(key)?; for child in children { match unmount_component_tree(child, component_store, layout_store) { @@ -327,8 +327,8 @@ fn unmount_component_tree( } /// Given a tree, will walk the branches until it finds the next root nodes to connect. -/// While this sounds slow, in practice it rarely has to go far in any direction. This could -/// potentially be done away with some hoisting magic in the `mount()` recursion, but I couldn't +/// While this sounds slow, in practice it rarely has to go far in any direction. This could +/// potentially be done away with some hoisting magic in the `mount()` recursion, but I couldn't /// find a pattern that didn't feel like some utter magic in Rust. /// /// It might be because I'm writing this at 3AM. Feel free to improve it. @@ -337,7 +337,7 @@ fn link_layout_nodess( child: ComponentKey, components: &mut ComponentStore, layouts: &mut LayoutStore -) -> Result<(), Box> { +) -> Result<(), Box> { if let (Ok(parent_instance), Ok(child_instance)) = (components.get(parent), components.get(child)) { if let (Some(parent_layout), Some(child_layout)) = (parent_instance.layout, child_instance.layout) { layouts.add_child(parent_layout, child_layout)?; @@ -364,7 +364,7 @@ fn walk_and_apply_styles( key: ComponentKey, components: &mut ComponentStore, layouts: &mut LayoutStore -) -> Result<(), Box> { +) -> Result<(), Box> { let instance = components.get_mut(key)?; if let Some(layout_key) = instance.layout { diff --git a/lifecycle/src/rsx/mod.rs b/lifecycle/src/rsx/mod.rs index 6278f36..1bc224c 100644 --- a/lifecycle/src/rsx/mod.rs +++ b/lifecycle/src/rsx/mod.rs @@ -31,7 +31,7 @@ impl RSX { pub fn node( tag: &'static str, styles: StylesList, - create_fn: fn(key: ComponentKey) -> Box, + create_fn: fn(key: ComponentKey) -> Box, props: P, children: Vec ) -> RSX { @@ -43,9 +43,9 @@ impl RSX { children: children }) } - + /// Shorthand method for creating a new `RSX::VirtualText` instance. Rarely should you call - /// this yourself; the `rsx! {}` and `text!()` macros handle this for you. + /// this yourself; the `rsx! {}` and `text!()` macros handle this for you. pub fn text(s: String) -> RSX { RSX::VirtualText(VirtualText(s)) } diff --git a/lifecycle/src/rsx/virtual_node.rs b/lifecycle/src/rsx/virtual_node.rs index aa15630..f5b8f3a 100644 --- a/lifecycle/src/rsx/virtual_node.rs +++ b/lifecycle/src/rsx/virtual_node.rs @@ -22,12 +22,12 @@ pub struct VirtualNode { /// `Component` instances are created on-demand, if the reconciler deems it be so. This /// is a closure that should return an instance of the correct type. - pub create_component_fn: fn(key: ComponentKey) -> Box, + pub create_component_fn: fn(key: ComponentKey) -> Box, /// When some RSX is returned, we scoop up the props inside a special block, and then shove - /// them in here as an `Any` object. When you `derive(Props)` on a `Component` struct, it + /// them in here as an `Any` object. When you `derive(Props)` on a `Component` struct, it /// creates a setter that specifically handles downcasting and persisting props for you. - pub props: Box, + pub props: Box, /// Child components for this node. pub children: Vec diff --git a/lifecycle/src/traits.rs b/lifecycle/src/traits.rs index 1a1d6d6..8119907 100644 --- a/lifecycle/src/traits.rs +++ b/lifecycle/src/traits.rs @@ -45,7 +45,7 @@ pub trait AppDelegate: Send + Sync { fn will_resign_active(&mut self) {} /// Fired when an Application has resigned active. - fn did_resign_active(&mut self) {} + fn did_resign_active(&mut self) {} /// Fired when an Application is going to terminate. You can use this to, say, instruct the /// system to "wait a minute, lemme finish". @@ -73,11 +73,11 @@ pub trait WindowDelegate: Send + Sync { } pub trait Props { - fn set_props(&mut self, new_props: &mut Any); + fn set_props(&mut self, new_props: &mut dyn Any); } /// The `Component` lifecycle, mostly inspired from React, with a few extra methods for views that -/// need to have a backing native layer. A good breakdown of the React Component lifecycle can be +/// need to have a backing native layer. A good breakdown of the React Component lifecycle can be /// found [in this tweet](https://twitter.com/dan_abramov/status/981712092611989509?lang=en). /// /// Alchemy does not currently implement Hooks, and at the moment has no plans to do so (the API @@ -106,7 +106,7 @@ pub trait Component: Props + Send + Sync { /// `node`, you need to instruct the system how to remove it from the tree at your point. fn remove_child_node(&self, _component: PlatformSpecificNodeType) {} - /// Given a configured 'appearance' and computed `layout`, this method should transform them + /// Given a configured 'appearance' and computed `layout`, this method should transform them /// into appropriate calls to the backing native node. fn apply_styles(&self, _appearance: &Appearance, _layout: &Layout) {} @@ -114,80 +114,80 @@ pub trait Component: Props + Send + Sync { /// It should return an object to update the state, or null to update nothing. /// This method exists for rare use cases where the state depends on changes in props over time. fn get_derived_state_from_props(&self) {} - + /// Invoked right before the most recently rendered output is committed to the backing layer tree. - /// It enables your component to capture some information from the tree (e.g. scroll position) before it's - /// potentially changed. Any value returned by this lifecycle will be passed as a parameter + /// It enables your component to capture some information from the tree (e.g. scroll position) before it's + /// potentially changed. Any value returned by this lifecycle will be passed as a parameter /// to component_did_update(). - /// - /// This use case is not common, but it may occur in UIs like a chat thread that need to handle scroll + /// + /// This use case is not common, but it may occur in UIs like a chat thread that need to handle scroll /// position in a special way. A snapshot value (or None) should be returned. fn get_snapshot_before_update(&self) {} /// Invoked immediately after a component is mounted (inserted into the tree). /// If you need to load data from a remote endpoint, this is a good place to instantiate the network request. - /// This method is also a good place to set up any subscriptions. If you do that, don’t forget to unsubscribe + /// This method is also a good place to set up any subscriptions. If you do that, don’t forget to unsubscribe /// in component_will_unmount(). fn component_did_mount(&mut self) {} /// Invoked immediately after updating occurs. This method is not called for the initial render. - /// This is also a good place to do network requests as long as you compare the current props to previous props + /// This is also a good place to do network requests as long as you compare the current props to previous props /// (e.g. a network request may not be necessary if the props have not changed). fn component_did_update(&mut self) {} - /// Invoked immediately before a component is unmounted and destroyed. Perform any necessary cleanup in this - /// method, such as invalidating timers, canceling network requests, or cleaning up any subscriptions that + /// Invoked immediately before a component is unmounted and destroyed. Perform any necessary cleanup in this + /// method, such as invalidating timers, canceling network requests, or cleaning up any subscriptions that /// were created in component_did_mount(). - /// - /// You should not call set state in this method because the component will never be re-rendered. Once a + /// + /// You should not call set state in this method because the component will never be re-rendered. Once a /// component instance is unmounted, it will never be mounted again. fn component_will_unmount(&mut self) {} - /// Invoked after an error has been thrown by a descendant component. Called during the "commit" phase, + /// Invoked after an error has been thrown by a descendant component. Called during the "commit" phase, /// so side-effects are permitted. It should be used for things like logging errors (e.g, /// Sentry). fn component_did_catch(&mut self /* error: */) {} - /// Use this to let Alchemy know if a component’s output is not affected by the current change in state - /// or props. The default behavior is to re-render on every state change, and in the vast majority of + /// Use this to let Alchemy know if a component’s output is not affected by the current change in state + /// or props. The default behavior is to re-render on every state change, and in the vast majority of /// cases you should rely on the default behavior. /// - /// This is invoked before rendering when new props or state are being received. Defaults to true. This - /// method is not called for the initial render or when force_update() is used. This method only exists + /// This is invoked before rendering when new props or state are being received. Defaults to true. This + /// method is not called for the initial render or when force_update() is used. This method only exists /// as a performance optimization. Do not rely on it to “prevent” a rendering, as this can lead to bugs. fn should_component_update(&self) -> bool { true } /// The only required method for a `Component`. Should return a Result of RSX nodes, or an /// Error (in very rare cases, such as trying to get a key from a strange HashMap or - /// something). + /// something). /// - /// The render() function should be pure, meaning that it does not modify component state, it - /// returns the same result each time it’s invoked, and it does not directly interact with the + /// The render() function should be pure, meaning that it does not modify component state, it + /// returns the same result each time it’s invoked, and it does not directly interact with the /// backing rendering framework. /// - /// If you need to interact with the native layer, perform your work in component_did_mount() or the other + /// If you need to interact with the native layer, perform your work in component_did_mount() or the other /// lifecycle methods instead. Keeping `render()` pure makes components easier to think about. /// /// This method is not called if should_component_update() returns `false`. fn render(&self, children: Vec) -> Result { Ok(RSX::None) } - /// This lifecycle is invoked after an error has been thrown by a descendant component. It receives + /// This lifecycle is invoked after an error has been thrown by a descendant component. It receives /// the error that was thrown as a parameter and should return a value to update state. /// - /// This is called during the "render" phase, so side-effects are not permitted. + /// This is called during the "render" phase, so side-effects are not permitted. /// For those use cases, use component_did_catch() instead. fn get_derived_state_from_error(&self, _error: ()) {} - /// By default, when your component’s state or props change, your component will re-render. - /// If your `render()` method depends on some other data, you can tell Alchemy that the component + /// By default, when your component’s state or props change, your component will re-render. + /// If your `render()` method depends on some other data, you can tell Alchemy that the component /// needs re-rendering by calling `force_update()`. /// - /// Calling `force_update()` will cause `render()` to be called on the component, skipping - /// `should_component_update()`. This will trigger the normal lifecycle methods for child components, - /// including the `should_component_update()` method of each child. Alchemy will still only update the + /// Calling `force_update()` will cause `render()` to be called on the component, skipping + /// `should_component_update()`. This will trigger the normal lifecycle methods for child components, + /// including the `should_component_update()` method of each child. Alchemy will still only update the /// backing widget tree if the markup changes. /// - /// Normally, you should try to avoid all uses of `force_update()` and only read from `this.props` + /// Normally, you should try to avoid all uses of `force_update()` and only read from `this.props` /// and `this.state` in `render()`. fn force_update(&self) {} } diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 2aeaa11..0000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -1.35.0 diff --git a/styles/src/color.rs b/styles/src/color.rs index cf55bc4..f5942ae 100644 --- a/styles/src/color.rs +++ b/styles/src/color.rs @@ -51,10 +51,10 @@ impl Color { #[inline] pub fn new(red: u8, green: u8, blue: u8, alpha: u8) -> Self { Color { - red: red, - green: green, - blue: blue, - alpha: alpha, + red, + green, + blue, + alpha, } } @@ -81,7 +81,7 @@ impl Color { pub fn alpha_f32(&self) -> f32 { self.alpha as f32 / 255.0 } - + /// Parse a value, per CSS Color Module Level 3. /// /// FIXME(#2) Deprecated CSS2 System Colors are not supported yet. @@ -501,9 +501,9 @@ pub fn parse_color_keyword(ident: &str) -> Result { #[inline] fn from_hex(c: u8) -> Result { match c { - b'0'...b'9' => Ok(c - b'0'), - b'a'...b'f' => Ok(c - b'a' + 10), - b'A'...b'F' => Ok(c - b'A' + 10), + b'0'..=b'9' => Ok(c - b'0'), + b'a'..=b'f' => Ok(c - b'a' + 10), + b'A'..=b'F' => Ok(c - b'A' + 10), _ => Err(()), } } @@ -663,5 +663,5 @@ where let red = clamp_unit_f32(hue_to_rgb(m1, m2, hue_times_3 + 1.)); let green = clamp_unit_f32(hue_to_rgb(m1, m2, hue_times_3)); let blue = clamp_unit_f32(hue_to_rgb(m1, m2, hue_times_3 - 1.)); - return Ok((red, green, blue, uses_commas)); + Ok((red, green, blue, uses_commas)) } diff --git a/styles/src/stretch/algo.rs b/styles/src/stretch/algo.rs index 8ef6948..1632281 100644 --- a/styles/src/stretch/algo.rs +++ b/styles/src/stretch/algo.rs @@ -54,7 +54,7 @@ struct FlexLine { } impl Stretch { - pub(crate) fn compute(&mut self, root: Node, size: Size) -> Result<(), Box> { + pub(crate) fn compute(&mut self, root: Node, size: Size) -> Result<(), Box> { let style = self.style[&root]; let has_root_min_max = style.min_size.width.is_defined() || style.min_size.height.is_defined() @@ -133,7 +133,7 @@ impl Stretch { node_size: Size, parent_size: Size, perform_layout: bool, - ) -> Result> { + ) -> Result> { *self.is_dirty.get_mut(node).unwrap() = false; // First we check if we have a result for the given input @@ -277,7 +277,7 @@ impl Stretch { // TODO - this does not follow spec. See commented out code below // 3. Determine the flex base size and hypothetical main size of each item: - flex_items.iter_mut().try_for_each(|child| -> Result<(), Box> { + flex_items.iter_mut().try_for_each(|child| -> Result<(), Box> { let child_style = self.style[&child.node]; // A. If the item has a definite used flex basis, that’s the flex base size. @@ -364,7 +364,7 @@ impl Stretch { // The hypothetical main size is the item’s flex base size clamped according to its // used min and max main sizes (and flooring the content box size at zero). - flex_items.iter_mut().try_for_each(|child| -> Result<(), Box> { + flex_items.iter_mut().try_for_each(|child| -> Result<(), Box> { child.inner_flex_basis = child.flex_basis - child.padding.main(dir) - child.border.main(dir); // TODO - not really spec abiding but needs to be done somewhere. probably somewhere else though. @@ -441,7 +441,7 @@ impl Stretch { // // 9.7. Resolving Flexible Lengths - flex_lines.iter_mut().try_for_each(|line| -> Result<(), Box> { + flex_lines.iter_mut().try_for_each(|line| -> Result<(), Box> { // 1. Determine the used flex factor. Sum the outer hypothetical main sizes of all // items on the line. If the sum is less than the flex container’s inner main size, // use the flex grow factor for the rest of this algorithm; otherwise, use the @@ -458,7 +458,7 @@ impl Stretch { // - If using the flex shrink factor: any item that has a flex base size // smaller than its hypothetical main size - line.items.iter_mut().try_for_each(|child| -> Result<(), Box> { + line.items.iter_mut().try_for_each(|child| -> Result<(), Box> { // TODO - This is not found by reading the spec. Maybe this can be done in some other place // instead. This was found by trail and error fixing tests to align with webkit output. if node_inner_size.main(dir).is_undefined() && is_row { @@ -614,7 +614,7 @@ impl Stretch { // item’s target main size was made smaller by this, it’s a max violation. // If the item’s target main size was made larger by this, it’s a min violation. - let total_violation = unfrozen.iter_mut().try_fold(0.0, |acc, child| -> Result> { + let total_violation = unfrozen.iter_mut().try_fold(0.0, |acc, child| -> Result> { // TODO - not really spec abiding but needs to be done somewhere. probably somewhere else though. // The following logic was developed not from the spec but by trail and error looking into how // webkit handled various scenarios. Can probably be solved better by passing in @@ -691,7 +691,7 @@ impl Stretch { // used main size and the available space, treating auto as fit-content. flex_lines.iter_mut().try_for_each(|line| { - line.items.iter_mut().try_for_each(|child| -> Result<(), Box> { + line.items.iter_mut().try_for_each(|child| -> Result<(), Box> { let child_cross = child.size.cross(dir).maybe_max(child.min_size.cross(dir)).maybe_min(child.max_size.cross(dir)); @@ -737,7 +737,7 @@ impl Stretch { if has_baseline_child { flex_lines.iter_mut().try_for_each(|line| { - line.items.iter_mut().try_for_each(|child| -> Result<(), Box> { + line.items.iter_mut().try_for_each(|child| -> Result<(), Box> { let result = self.compute_internal( child.node, Size { @@ -1148,12 +1148,12 @@ impl Stretch { let mut lines: Vec> = vec![]; let mut total_offset_cross = padding_border.cross_start(dir); - let layout_line = |line: &mut FlexLine| -> Result<(), Box> { + let layout_line = |line: &mut FlexLine| -> Result<(), Box> { let mut children: Vec = vec![]; let mut total_offset_main = padding_border.main_start(dir); let line_offset_cross = line.offset_cross; - let layout_item = |child: &mut FlexItem| -> Result<(), Box> { + let layout_item = |child: &mut FlexItem| -> Result<(), Box> { let result = self.compute_internal( child.node, child.target_size.map(|s| s.to_number()), diff --git a/styles/src/stretch/mod.rs b/styles/src/stretch/mod.rs index 4eedcf3..5a17d4f 100644 --- a/styles/src/stretch/mod.rs +++ b/styles/src/stretch/mod.rs @@ -15,7 +15,7 @@ use core::any::Any; #[derive(Debug)] pub enum Error { InvalidNode(node::Node), - Measure(Box), + Measure(Box), } impl std::fmt::Display for Error { diff --git a/styles/src/stretch/node.rs b/styles/src/stretch/node.rs index 52b9e46..d612b79 100644 --- a/styles/src/stretch/node.rs +++ b/styles/src/stretch/node.rs @@ -16,7 +16,7 @@ use crate::stretch::result::{Cache, Layout}; use crate::stretch::style::*; use crate::stretch::Error; -type MeasureFunc = Box) -> Result, Box> + Send + Sync + 'static>; +type MeasureFunc = Box) -> Result, Box> + Send + Sync + 'static>; lazy_static! { /// Global stretch instance id allocator. diff --git a/styles/src/styles_parser.rs b/styles/src/styles_parser.rs index c6e36e2..e6118c2 100644 --- a/styles/src/styles_parser.rs +++ b/styles/src/styles_parser.rs @@ -67,7 +67,7 @@ impl<'i> QualifiedRuleParser<'i> for RuleParser { let styles = DeclarationListParser::new(input, StyleParser {}).collect::>(); Ok(Rule { - key: key, + key, styles: styles.into_iter().filter_map(|decl| { if !decl.is_ok() { eprintln!("{:?}", decl); @@ -119,7 +119,7 @@ impl<'i> DeclarationParser<'i> for StyleParser { "space-around" => Styles::AlignContent(AlignContent::SpaceAround), _ => { return Err(s.new_unexpected_token_error(t.clone())); } }}, - + "align-items" => { let s = input.current_source_location(); let t = input.next()?; match ident(&t) { "flex-start" => Styles::AlignItems(AlignItems::FlexStart), "flex-end" => Styles::AlignItems(AlignItems::FlexEnd), @@ -128,7 +128,7 @@ impl<'i> DeclarationParser<'i> for StyleParser { "stretch" => Styles::AlignItems(AlignItems::Stretch), _ => { return Err(s.new_unexpected_token_error(t.clone())); } }}, - + "align_self" => { let s = input.current_source_location(); let t = input.next()?; match ident(&t) { "auto" => Styles::AlignSelf(AlignSelf::Auto), "flex-start" => Styles::AlignSelf(AlignSelf::FlexStart), @@ -149,14 +149,14 @@ impl<'i> DeclarationParser<'i> for StyleParser { }}, "background-color" => Styles::BackgroundColor(Color::parse(input)?), - + // Border values~ "border-color" => Styles::BorderColor(Color::parse(input)?), "border-top-color" => Styles::BorderTopColor(Color::parse(input)?), "border-bottom-color" => Styles::BorderBottomColor(Color::parse(input)?), "border-left-color" => Styles::BorderLeftColor(Color::parse(input)?), "border-right-color" => Styles::BorderRightColor(Color::parse(input)?), - + "bottom" => Styles::Bottom(parse_floaty_mcfloatface_value(input)?), "color" => Styles::TextColor(Color::parse(input)?), @@ -173,11 +173,11 @@ impl<'i> DeclarationParser<'i> for StyleParser { "none" => Styles::Display(Display::None), _ => { return Err(s.new_unexpected_token_error(t.clone())); } }}, - + "end" => Styles::End(parse_floaty_mcfloatface_value(input)?), "flex-basis" => Styles::FlexBasis(parse_floaty_mcfloatface_value(input)?), - + "flex-direction" => { let s = input.current_source_location(); let t = input.next()?; match ident(&t) { "row" => Styles::FlexDirection(FlexDirection::Row), "row-reverse" => Styles::FlexDirection(FlexDirection::RowReverse), @@ -188,17 +188,17 @@ impl<'i> DeclarationParser<'i> for StyleParser { "flex-grow" => Styles::FlexGrow(parse_floaty_mcfloatface_value(input)?), "flex-shrink" => Styles::FlexShrink(parse_floaty_mcfloatface_value(input)?), - + "flex-wrap" => { let s = input.current_source_location(); let t = input.next()?; match ident(&t) { "no-wrap" => Styles::FlexWrap(FlexWrap::NoWrap), "wrap" => Styles::FlexWrap(FlexWrap::Wrap), "wrap-reverse" => Styles::FlexWrap(FlexWrap::WrapReverse), _ => { return Err(s.new_unexpected_token_error(t.clone())); } }}, - + //FontFamily(FontFamily), "font-size" => Styles::FontSize(parse_floaty_mcfloatface_value(input)?), - + "font-style" => { let s = input.current_source_location(); let t = input.next()?; match ident(&t) { "normal" => Styles::FontStyle(FontStyle::Normal), "italic" => Styles::FontStyle(FontStyle::Italic), @@ -211,7 +211,7 @@ impl<'i> DeclarationParser<'i> for StyleParser { "bold" => Styles::FontWeight(FontWeight::Bold), _ => { return Err(s.new_unexpected_token_error(t.clone())); } }}, - + "height" => Styles::Height(parse_floaty_mcfloatface_value(input)?), "justify-content" => { let s = input.current_source_location(); let t = input.next()?; match ident(&t) { @@ -223,7 +223,7 @@ impl<'i> DeclarationParser<'i> for StyleParser { "space-evenly" => Styles::JustifyContent(JustifyContent::SpaceEvenly), _ => { return Err(s.new_unexpected_token_error(t.clone())); } }}, - + "left" => Styles::Left(parse_floaty_mcfloatface_value(input)?), "line-height" => Styles::FontLineHeight(parse_floaty_mcfloatface_value(input)?), @@ -236,35 +236,35 @@ impl<'i> DeclarationParser<'i> for StyleParser { "max-height" => Styles::MaxHeight(parse_floaty_mcfloatface_value(input)?), "max-width" => Styles::MaxWidth(parse_floaty_mcfloatface_value(input)?), - + "min-height" => Styles::MinHeight(parse_floaty_mcfloatface_value(input)?), "min-width" => Styles::MinWidth(parse_floaty_mcfloatface_value(input)?), "opacity" => Styles::Opacity(parse_floaty_mcfloatface_value(input)?), - + "overflow" => { let s = input.current_source_location(); let t = input.next()?; match ident(&t) { "visible" => Styles::Overflow(Overflow::Visible), "hidden" => Styles::Overflow(Overflow::Hidden), "scroll" => Styles::Overflow(Overflow::Scroll), _ => { return Err(s.new_unexpected_token_error(t.clone())); } }}, - + "padding-bottom" => Styles::PaddingBottom(parse_floaty_mcfloatface_value(input)?), "padding-end" => Styles::PaddingEnd(parse_floaty_mcfloatface_value(input)?), "padding-left" => Styles::PaddingLeft(parse_floaty_mcfloatface_value(input)?), "padding-right" => Styles::PaddingRight(parse_floaty_mcfloatface_value(input)?), "padding-start" => Styles::PaddingStart(parse_floaty_mcfloatface_value(input)?), "padding-top" => Styles::PaddingTop(parse_floaty_mcfloatface_value(input)?), - + "position" => { let s = input.current_source_location(); let t = input.next()?; match ident(&t) { "absolute" => Styles::PositionType(PositionType::Absolute), "relative" => Styles::PositionType(PositionType::Relative), _ => { return Err(s.new_unexpected_token_error(t.clone())); } }}, - + "right" => Styles::Right(parse_floaty_mcfloatface_value(input)?), "start" => Styles::Start(parse_floaty_mcfloatface_value(input)?), - + "text-align" => { let s = input.current_source_location(); let t = input.next()?; match ident(&t) { "auto" => Styles::TextAlignment(TextAlignment::Auto), "left" => Styles::TextAlignment(TextAlignment::Left), @@ -273,14 +273,14 @@ impl<'i> DeclarationParser<'i> for StyleParser { "justify" => Styles::TextAlignment(TextAlignment::Justify), _ => { return Err(s.new_unexpected_token_error(t.clone())); } }}, - + "text-decoration-color" => Styles::TextDecorationColor(Color::parse(input)?), "text-shadow-color" => Styles::TextShadowColor(Color::parse(input)?), "tint-color" => Styles::TintColor(Color::parse(input)?), - + "top" => Styles::Top(parse_floaty_mcfloatface_value(input)?), "width" => Styles::Width(parse_floaty_mcfloatface_value(input)?), - + t => { let location = input.current_source_location(); return Err(location.new_unexpected_token_error(Token::Ident(t.to_string().into()))); @@ -298,7 +298,7 @@ fn parse_floaty_mcfloatface_value<'i, 't>(input: &mut Parser<'i, 't>) -> Result< let token = input.next()?; match token { - Token::Number { value, .. } => Ok(*value), + Token::Number { value, .. } => Ok(*value), _ => Err(location.new_basic_unexpected_token_error(token.clone())) } }