Skip to content

Commit

Permalink
refactor: use core instead of std where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ccbrown committed Dec 10, 2024
1 parent fbaca5f commit e4fe60b
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 33 deletions.
6 changes: 3 additions & 3 deletions packages/iocraft/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C: Component> {
Expand Down
4 changes: 2 additions & 2 deletions packages/iocraft/src/components/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/iocraft/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{
use core::{
any::Any,
cell::{Ref, RefCell, RefMut},
mem,
Expand Down
2 changes: 1 addition & 1 deletion packages/iocraft/src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{
use core::{
mem,
ops::{Deref, DerefMut},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/iocraft/src/hook.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{ComponentDrawer, ComponentUpdater, ContextStack};
use std::{
use core::{
any::Any,
pin::Pin,
task::{Context, Poll},
Expand Down
6 changes: 3 additions & 3 deletions packages/iocraft/src/hooks/use_async_handler.rs
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down
2 changes: 1 addition & 1 deletion packages/iocraft/src/hooks/use_context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::Hooks;
use std::{
use core::{
any::Any,
cell::{Ref, RefMut},
};
Expand Down
4 changes: 2 additions & 2 deletions packages/iocraft/src/hooks/use_future.rs
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down
10 changes: 5 additions & 5 deletions packages/iocraft/src/hooks/use_output.rs
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down Expand Up @@ -173,23 +173,23 @@ 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
);

let stdout = use_output.use_stdout();
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(())
);

let stderr = use_output.use_stderr();
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(())
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/iocraft/src/hooks/use_state.rs
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down Expand Up @@ -266,8 +266,8 @@ impl<T: cmp::Eq + Sync + Send + 'static> cmp::Eq for State<T> {}
#[cfg(test)]
mod tests {
use super::*;
use core::pin::Pin;
use futures::task::noop_waker;
use std::pin::Pin;

#[test]
fn test_state() {
Expand Down
4 changes: 2 additions & 2 deletions packages/iocraft/src/hooks/use_terminal_events.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/iocraft/src/props.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::marker::PhantomData;
use core::marker::PhantomData;

/// This trait makes a struct available for use as component properties.
///
Expand Down
17 changes: 9 additions & 8 deletions packages/iocraft/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e4fe60b

Please sign in to comment.