fix no_std

This commit is contained in:
koe 2024-09-01 14:05:21 -05:00 • committed by Jeremy Soller
parent cdf1e5b4ee
commit c65f299e87
3 changed files with 11 additions and 9 deletions

View file

@ -1,5 +1,6 @@
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use alloc::{string::String, vec::Vec}; use alloc::{string::String, vec::Vec};
use core::mem;
use crate::{ use crate::{
Align, Attrs, AttrsList, Cached, FontSystem, LayoutLine, LineEnding, ShapeBuffer, ShapeLine, Align, Attrs, AttrsList, Cached, FontSystem, LayoutLine, LineEnding, ShapeBuffer, ShapeLine,
@ -327,14 +328,14 @@ impl BufferLine {
/// ///
/// The buffer line is in an invalid state after this is called. See [`Self::reset_new`]. /// The buffer line is in an invalid state after this is called. See [`Self::reset_new`].
pub(crate) fn reclaim_attrs(&mut self) -> AttrsList { pub(crate) fn reclaim_attrs(&mut self) -> AttrsList {
std::mem::replace(&mut self.attrs_list, AttrsList::new(Attrs::new())) mem::replace(&mut self.attrs_list, AttrsList::new(Attrs::new()))
} }
/// Reclaim text memory that isn't needed any longer. /// Reclaim text memory that isn't needed any longer.
/// ///
/// The buffer line is in an invalid state after this is called. See [`Self::reset_new`]. /// The buffer line is in an invalid state after this is called. See [`Self::reset_new`].
pub(crate) fn reclaim_text(&mut self) -> String { pub(crate) fn reclaim_text(&mut self) -> String {
let mut text = std::mem::take(&mut self.text); let mut text = mem::take(&mut self.text);
text.clear(); text.clear();
text text
} }

View file

@ -1,4 +1,5 @@
use core::fmt::Debug; use core::fmt::Debug;
use core::mem;
/// Helper for caching a value when the value is optionally present in the 'unused' state. /// Helper for caching a value when the value is optionally present in the 'unused' state.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -44,7 +45,7 @@ impl<T: Clone + Debug> Cached<T> {
/// Takes the buffered value if in state `Self::Unused`. /// Takes the buffered value if in state `Self::Unused`.
pub fn take_unused(&mut self) -> Option<T> { pub fn take_unused(&mut self) -> Option<T> {
if matches!(*self, Self::Unused(_)) { if matches!(*self, Self::Unused(_)) {
let Self::Unused(val) = std::mem::replace(self, Self::Empty) else { let Self::Unused(val) = mem::replace(self, Self::Empty) else {
unreachable!() unreachable!()
}; };
Some(val) Some(val)
@ -56,7 +57,7 @@ impl<T: Clone + Debug> Cached<T> {
/// Takes the cached value if in state `Self::Used`. /// Takes the cached value if in state `Self::Used`.
pub fn take_used(&mut self) -> Option<T> { pub fn take_used(&mut self) -> Option<T> {
if matches!(*self, Self::Used(_)) { if matches!(*self, Self::Used(_)) {
let Self::Used(val) = std::mem::replace(self, Self::Empty) else { let Self::Used(val) = mem::replace(self, Self::Empty) else {
unreachable!() unreachable!()
}; };
Some(val) Some(val)

View file

@ -632,7 +632,7 @@ impl ShapeWord {
word word
); );
let mut glyphs = std::mem::take(&mut self.glyphs); let mut glyphs = mem::take(&mut self.glyphs);
glyphs.clear(); glyphs.clear();
let span_rtl = level.is_rtl(); let span_rtl = level.is_rtl();
@ -771,10 +771,10 @@ impl ShapeSpan {
span span
); );
let mut words = std::mem::take(&mut self.words); let mut words = mem::take(&mut self.words);
// Cache the shape words in reverse order so they can be popped for reuse in the same order. // Cache the shape words in reverse order so they can be popped for reuse in the same order.
let mut cached_words = std::mem::take(&mut scratch.words); let mut cached_words = mem::take(&mut scratch.words);
cached_words.clear(); cached_words.clear();
if line_rtl != level.is_rtl() { if line_rtl != level.is_rtl() {
// Un-reverse previous words so the internal glyph counts match accurately when rewriting memory. // Un-reverse previous words so the internal glyph counts match accurately when rewriting memory.
@ -941,10 +941,10 @@ impl ShapeLine {
shaping: Shaping, shaping: Shaping,
tab_width: u16, tab_width: u16,
) { ) {
let mut spans = std::mem::take(&mut self.spans); let mut spans = mem::take(&mut self.spans);
// Cache the shape spans in reverse order so they can be popped for reuse in the same order. // Cache the shape spans in reverse order so they can be popped for reuse in the same order.
let mut cached_spans = std::mem::take(&mut scratch.spans); let mut cached_spans = mem::take(&mut scratch.spans);
cached_spans.clear(); cached_spans.clear();
cached_spans.extend(spans.drain(..).rev()); cached_spans.extend(spans.drain(..).rev());