From 36aead9762bdeae7306b7c226420e05ce8f1059a Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Sun, 1 Dec 2024 16:17:51 +0100 Subject: [PATCH] src: use core instead of std in some places, aiming for no_std compat --- src/geometry.rs | 8 ++++---- src/lib8/interpolate.rs | 2 +- src/mappings.rs | 10 +++++----- src/platform/smart_leds_lib.rs | 4 ++-- src/render.rs | 2 +- src/task.rs | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/geometry.rs b/src/geometry.rs index 3ee84d7..bed20ad 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -1,7 +1,7 @@ -use std::fmt::{Debug, Formatter}; -use std::ops::{Mul, Sub, Add}; +use core::fmt::{Debug, Formatter}; +use core::ops::{Mul, Sub, Add}; use num::{One, pow, integer::Roots}; -use std::cmp::{min, max}; +use core::cmp::{min, max}; pub trait CoordinateOp: PartialOrd + PartialEq + Sub + Clone + Mul + Copy + One + Add + Eq + Debug where Self: Sub { @@ -21,7 +21,7 @@ pub struct Coordinates { } impl Debug for Coordinates where S::Data: Debug { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { f.debug_tuple("@") .field(&self.x) .field(&self.y) diff --git a/src/lib8/interpolate.rs b/src/lib8/interpolate.rs index 804ffd0..10f5d21 100644 --- a/src/lib8/interpolate.rs +++ b/src/lib8/interpolate.rs @@ -1,5 +1,5 @@ use num::PrimInt; -use std::ops::BitOr; +use core::ops::BitOr; use rgb::Rgb; diff --git a/src/mappings.rs b/src/mappings.rs index 4569e1b..55b4c2a 100644 --- a/src/mappings.rs +++ b/src/mappings.rs @@ -2,8 +2,8 @@ use crate::geometry::*; use crate::lib8::interpolate::scale8; -use std::cmp::{max, min}; -use std::fmt::{Formatter, Debug}; +use core::cmp::{max, min}; +use core::fmt::{Formatter, Debug}; pub trait CoordinateView<'a>: Debug { type Space: CoordinateSpace; @@ -216,7 +216,7 @@ pub struct StrideView<'a> { } impl<'a> Debug for StrideView<'a> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { f.debug_struct("StrideView") .field("range", &self.range) .field("step", &self.step_size) @@ -247,8 +247,8 @@ impl<'a> StrideView<'a> { (map.size.width(), map.size.height()) ); let step_size = VirtualCoordinates::new( - u8::MAX / std::cmp::max(1, range.width()), - u8::MAX / std::cmp::max(1, range.height()) + u8::MAX / core::cmp::max(1, range.width()), + u8::MAX / core::cmp::max(1, range.height()) //scale8(255, std::cmp::max(1, range.bottom_right.x - range.top_left.x)), //scale8(255, std::cmp::max(1, range.bottom_right.y - range.top_left.y)) ); diff --git a/src/platform/smart_leds_lib.rs b/src/platform/smart_leds_lib.rs index c95817b..dac190f 100644 --- a/src/platform/smart_leds_lib.rs +++ b/src/platform/smart_leds_lib.rs @@ -6,7 +6,7 @@ use crate::power::brightness_for_mw; use crate::geometry::*; use crate::mappings::*; -use std::fmt::Debug; +use core::fmt::Debug; struct StrideSampler<'a, P: Pixbuf> { pixbuf: &'a mut P, @@ -26,7 +26,7 @@ impl<'a, P: Pixbuf> PixelView for StrideSampler<'a, P> { } impl Debug for StrideOutput { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("StrideOutput").finish() } } diff --git a/src/render.rs b/src/render.rs index 633248f..4faa060 100644 --- a/src/render.rs +++ b/src/render.rs @@ -7,7 +7,7 @@ use crate::power::AsMilliwatts; use crate::task::Task; use crate::time::Periodically; use running_average::RealTimeRunningAverage; -use std::fmt::Debug; +use core::fmt::Debug; pub trait HardwarePixel: Send + Sync + Copy + AsMilliwatts + Default + From> + Fract8Ops {} impl HardwarePixel for T where T: Send + Sync + Copy + AsMilliwatts + Default + From> + Fract8Ops {} diff --git a/src/task.rs b/src/task.rs index 800b351..a7504e2 100644 --- a/src/task.rs +++ b/src/task.rs @@ -1,6 +1,6 @@ -use std::fmt; +use core::fmt; -pub trait Task: std::fmt::Debug { +pub trait Task: core::fmt::Debug { fn tick(&mut self) {} fn start(&mut self) {} fn stop(&mut self) {}