Skip to content

Commit

Permalink
fix no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
UkoeHB authored and jackpot51 committed Sep 1, 2024
1 parent cdf1e5b commit c65f299
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/buffer_line.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(not(feature = "std"))]
use alloc::{string::String, vec::Vec};
use core::mem;

use crate::{
Align, Attrs, AttrsList, Cached, FontSystem, LayoutLine, LineEnding, ShapeBuffer, ShapeLine,
Expand Down Expand Up @@ -327,14 +328,14 @@ impl BufferLine {
///
/// The buffer line is in an invalid state after this is called. See [`Self::reset_new`].
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.
///
/// The buffer line is in an invalid state after this is called. See [`Self::reset_new`].
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
}
Expand Down
5 changes: 3 additions & 2 deletions src/cached.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::fmt::Debug;
use core::mem;

/// Helper for caching a value when the value is optionally present in the 'unused' state.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -44,7 +45,7 @@ impl<T: Clone + Debug> Cached<T> {
/// Takes the buffered value if in state `Self::Unused`.
pub fn take_unused(&mut self) -> Option<T> {
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!()
};
Some(val)
Expand All @@ -56,7 +57,7 @@ impl<T: Clone + Debug> Cached<T> {
/// Takes the cached value if in state `Self::Used`.
pub fn take_used(&mut self) -> Option<T> {
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!()
};
Some(val)
Expand Down
10 changes: 5 additions & 5 deletions src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ impl ShapeWord {
word
);

let mut glyphs = std::mem::take(&mut self.glyphs);
let mut glyphs = mem::take(&mut self.glyphs);
glyphs.clear();

let span_rtl = level.is_rtl();
Expand Down Expand Up @@ -771,10 +771,10 @@ impl ShapeSpan {
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.
let mut cached_words = std::mem::take(&mut scratch.words);
let mut cached_words = mem::take(&mut scratch.words);
cached_words.clear();
if line_rtl != level.is_rtl() {
// Un-reverse previous words so the internal glyph counts match accurately when rewriting memory.
Expand Down Expand Up @@ -941,10 +941,10 @@ impl ShapeLine {
shaping: Shaping,
tab_width: u16,
) {

Check warning on line 943 in src/shape.rs

View workflow job for this annotation

GitHub Actions / clippy

docs for function which may panic missing `# Panics` section

warning: docs for function which may panic missing `# Panics` section --> src/shape.rs:935:5 | 935 | / pub fn build_in_buffer( 936 | | &mut self, 937 | | scratch: &mut ShapeBuffer, 938 | | font_system: &mut FontSystem, ... | 942 | | tab_width: u16, 943 | | ) { | |_____^ | note: first possible panic found here --> src/shape.rs:962:13 | 962 | assert_eq!(line_rtl, rtl); | ^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc
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.
let mut cached_spans = std::mem::take(&mut scratch.spans);
let mut cached_spans = mem::take(&mut scratch.spans);
cached_spans.clear();
cached_spans.extend(spans.drain(..).rev());

Expand Down

0 comments on commit c65f299

Please sign in to comment.