From e4fe60bd44e927cb53a1b48658c9b1529f6d430a Mon Sep 17 00:00:00 2001 From: Chris Brown <1731074+ccbrown@users.noreply.github.com> Date: Tue, 10 Dec 2024 18:30:22 -0500 Subject: [PATCH] refactor: use core instead of std where possible --- packages/iocraft/src/component.rs | 6 +++--- packages/iocraft/src/components/text_input.rs | 4 ++-- packages/iocraft/src/context.rs | 2 +- packages/iocraft/src/handler.rs | 2 +- packages/iocraft/src/hook.rs | 2 +- packages/iocraft/src/hooks/use_async_handler.rs | 6 +++--- packages/iocraft/src/hooks/use_context.rs | 2 +- packages/iocraft/src/hooks/use_future.rs | 4 ++-- packages/iocraft/src/hooks/use_output.rs | 10 +++++----- packages/iocraft/src/hooks/use_state.rs | 6 +++--- .../iocraft/src/hooks/use_terminal_events.rs | 4 ++-- packages/iocraft/src/props.rs | 2 +- packages/iocraft/src/render.rs | 17 +++++++++-------- 13 files changed, 34 insertions(+), 33 deletions(-) diff --git a/packages/iocraft/src/component.rs b/packages/iocraft/src/component.rs index 3790614..c449898 100644 --- a/packages/iocraft/src/component.rs +++ b/packages/iocraft/src/component.rs @@ -5,14 +5,14 @@ use crate::{ props::{AnyProps, Props}, render::{ComponentDrawer, ComponentUpdater, UpdateContext}, }; -use futures::future::poll_fn; -use indexmap::IndexMap; -use std::{ +use core::{ any::{Any, TypeId}, marker::PhantomData, pin::Pin, task::{Context, Poll}, }; +use futures::future::poll_fn; +use indexmap::IndexMap; use taffy::NodeId; pub(crate) struct ComponentHelper { diff --git a/packages/iocraft/src/components/text_input.rs b/packages/iocraft/src/components/text_input.rs index 8930634..0fe8197 100644 --- a/packages/iocraft/src/components/text_input.rs +++ b/packages/iocraft/src/components/text_input.rs @@ -2,11 +2,11 @@ use crate::{ CanvasTextStyle, Color, Component, ComponentDrawer, ComponentUpdater, Handler, Hooks, KeyCode, KeyEvent, KeyEventKind, Props, TerminalEvent, TerminalEvents, }; -use futures::stream::Stream; -use std::{ +use core::{ pin::{pin, Pin}, task::{Context, Poll}, }; +use futures::stream::Stream; use unicode_width::UnicodeWidthStr; /// The props which can be passed to the [`TextInput`] component. diff --git a/packages/iocraft/src/context.rs b/packages/iocraft/src/context.rs index f211095..a8f0a88 100644 --- a/packages/iocraft/src/context.rs +++ b/packages/iocraft/src/context.rs @@ -1,4 +1,4 @@ -use std::{ +use core::{ any::Any, cell::{Ref, RefCell, RefMut}, mem, diff --git a/packages/iocraft/src/handler.rs b/packages/iocraft/src/handler.rs index 40fa677..ef02d26 100644 --- a/packages/iocraft/src/handler.rs +++ b/packages/iocraft/src/handler.rs @@ -1,4 +1,4 @@ -use std::{ +use core::{ mem, ops::{Deref, DerefMut}, }; diff --git a/packages/iocraft/src/hook.rs b/packages/iocraft/src/hook.rs index 266ab9c..0cb97fa 100644 --- a/packages/iocraft/src/hook.rs +++ b/packages/iocraft/src/hook.rs @@ -1,5 +1,5 @@ use crate::{ComponentDrawer, ComponentUpdater, ContextStack}; -use std::{ +use core::{ any::Any, pin::Pin, task::{Context, Poll}, diff --git a/packages/iocraft/src/hooks/use_async_handler.rs b/packages/iocraft/src/hooks/use_async_handler.rs index 771c14f..320ebe0 100644 --- a/packages/iocraft/src/hooks/use_async_handler.rs +++ b/packages/iocraft/src/hooks/use_async_handler.rs @@ -1,11 +1,11 @@ use crate::{Handler, Hook, Hooks}; -use futures::future::BoxFuture; -use std::{ +use core::{ future::Future, pin::Pin, - sync::{Arc, Mutex}, task::{Context, Poll, Waker}, }; +use futures::future::BoxFuture; +use std::sync::{Arc, Mutex}; mod private { pub trait Sealed {} diff --git a/packages/iocraft/src/hooks/use_context.rs b/packages/iocraft/src/hooks/use_context.rs index 5eb076c..9d399bf 100644 --- a/packages/iocraft/src/hooks/use_context.rs +++ b/packages/iocraft/src/hooks/use_context.rs @@ -1,5 +1,5 @@ use crate::Hooks; -use std::{ +use core::{ any::Any, cell::{Ref, RefMut}, }; diff --git a/packages/iocraft/src/hooks/use_future.rs b/packages/iocraft/src/hooks/use_future.rs index 8e1cd16..4cfb65a 100644 --- a/packages/iocraft/src/hooks/use_future.rs +++ b/packages/iocraft/src/hooks/use_future.rs @@ -1,10 +1,10 @@ use crate::{Hook, Hooks}; -use futures::future::BoxFuture; -use std::{ +use core::{ future::Future, pin::Pin, task::{Context, Poll}, }; +use futures::future::BoxFuture; mod private { pub trait Sealed {} diff --git a/packages/iocraft/src/hooks/use_output.rs b/packages/iocraft/src/hooks/use_output.rs index f3fde4a..9661fe7 100644 --- a/packages/iocraft/src/hooks/use_output.rs +++ b/packages/iocraft/src/hooks/use_output.rs @@ -1,9 +1,9 @@ use crate::{ComponentUpdater, Hook, Hooks}; -use std::{ +use core::{ pin::Pin, - sync::{Arc, Mutex}, task::{Context, Poll, Waker}, }; +use std::sync::{Arc, Mutex}; mod private { pub trait Sealed {} @@ -173,7 +173,7 @@ mod tests { let mut use_output = UseOutputImpl::default(); assert_eq!( Pin::new(&mut use_output) - .poll_change(&mut std::task::Context::from_waker(&noop_waker())), + .poll_change(&mut core::task::Context::from_waker(&noop_waker())), Poll::Pending ); @@ -181,7 +181,7 @@ mod tests { stdout.println("Hello, world!"); assert_eq!( Pin::new(&mut use_output) - .poll_change(&mut std::task::Context::from_waker(&noop_waker())), + .poll_change(&mut core::task::Context::from_waker(&noop_waker())), Poll::Ready(()) ); @@ -189,7 +189,7 @@ mod tests { stderr.println("Hello, error!"); assert_eq!( Pin::new(&mut use_output) - .poll_change(&mut std::task::Context::from_waker(&noop_waker())), + .poll_change(&mut core::task::Context::from_waker(&noop_waker())), Poll::Ready(()) ); } diff --git a/packages/iocraft/src/hooks/use_state.rs b/packages/iocraft/src/hooks/use_state.rs index e4bd4a7..3beab4f 100644 --- a/packages/iocraft/src/hooks/use_state.rs +++ b/packages/iocraft/src/hooks/use_state.rs @@ -1,12 +1,12 @@ use crate::{Hook, Hooks}; -use generational_box::{AnyStorage, GenerationalBox, Owner, SyncStorage}; -use std::{ +use core::{ cmp, fmt::{self, Debug, Display, Formatter}, ops, pin::Pin, task::{Context, Poll, Waker}, }; +use generational_box::{AnyStorage, GenerationalBox, Owner, SyncStorage}; mod private { pub trait Sealed {} @@ -266,8 +266,8 @@ impl cmp::Eq for State {} #[cfg(test)] mod tests { use super::*; + use core::pin::Pin; use futures::task::noop_waker; - use std::pin::Pin; #[test] fn test_state() { diff --git a/packages/iocraft/src/hooks/use_terminal_events.rs b/packages/iocraft/src/hooks/use_terminal_events.rs index cb258e3..0eff2b0 100644 --- a/packages/iocraft/src/hooks/use_terminal_events.rs +++ b/packages/iocraft/src/hooks/use_terminal_events.rs @@ -1,9 +1,9 @@ use crate::{ComponentUpdater, FullscreenMouseEvent, Hook, Hooks, TerminalEvent, TerminalEvents}; -use futures::stream::Stream; -use std::{ +use core::{ pin::{pin, Pin}, task::{Context, Poll}, }; +use futures::stream::Stream; use taffy::{Point, Size}; mod private { diff --git a/packages/iocraft/src/props.rs b/packages/iocraft/src/props.rs index 72d3a48..44b5031 100644 --- a/packages/iocraft/src/props.rs +++ b/packages/iocraft/src/props.rs @@ -1,4 +1,4 @@ -use std::marker::PhantomData; +use core::marker::PhantomData; /// This trait makes a struct available for use as component properties. /// diff --git a/packages/iocraft/src/render.rs b/packages/iocraft/src/render.rs index 9546129..7c98e7d 100644 --- a/packages/iocraft/src/render.rs +++ b/packages/iocraft/src/render.rs @@ -6,19 +6,20 @@ use crate::{ props::AnyProps, terminal::{MockTerminalConfig, MockTerminalOutputStream, Terminal, TerminalEvents}, }; +use core::{ + any::Any, + cell::{Ref, RefMut}, + mem, + pin::Pin, + task::{self, Poll}, +}; use crossterm::{execute, terminal}; use futures::{ future::{select, FutureExt, LocalBoxFuture}, stream::{Stream, StreamExt}, }; use indexmap::IndexMap; -use std::{ - any::Any, - cell::{Ref, RefMut}, - io, mem, - pin::Pin, - task::{self, Poll}, -}; +use std::io; use taffy::{AvailableSpace, Layout, NodeId, Point, Size, Style, TaffyTree}; use uuid::Uuid; @@ -468,9 +469,9 @@ where mod tests { use super::*; use crate::prelude::*; + use core::future::Future; use macro_rules_attribute::apply; use smol_macros::test; - use std::future::Future; #[derive(Default, Props)] struct MyInnerComponentProps {