Closed
Description
Previously discussed here: #1746
Problem
Currently, due to the usage of std
in ratatui
, its usage on embedded devices is very limited, mostly to Espressif’s MCUs based on Xtensa (nightly) and RISC-V architectures. It would be beneficial to be able to compile at least ratatui-core
(and ratatui-widgets
in the future) for bare-metal targets. I am convinced that it would be possible to run ratatui
on many more modern MCUs such as STM32H7XX.
Solution
Convert first ratatui-core
, and later ratatui-widgets
to no_std
implementations, add std
feature flag.
Plan
Important assumptions
- We should favor
alloc
andcore
instead ofstd
where possible and add linter rules for that. This is a simple non-breaking change and should be the first step in moving towardsno_std
support. - All cargo features should be additive - we should use
std
feature instead ofno_std
and list it in every other feature that requiresstd
.
Analysis of the current state of the codebase - ratatui-core
std
usages
| 🟢 - in core
| 🟡 - in alloc
| 🔴 - requires std
|
- 🟢 std::fmt::{Write, Display, Result, Formatter, Debug}
- 🟡 std::borrow::Cow
- 🟢 std::str::{from_utf8, FromStr}
- 🟢 std::ops::{Index, IndexMut, Add, Range}
- 🟢 std::cell::{RefCell}
- 🔴 std::collections::HashMap -
hashbrown::HashMap
is ano_std
drop-in replacement - 🟢 std::iter::*
- 🔴 std::io::Result
- 🟢 std::num::NonZeroUsize
- 🟡 std::rc::Rc
- 🟢 std::cmp::{max, min}
- 🟡 std::vec::IntoIter
- 🟢 std::slice::{Iter, IterMut}
- 🟢 std::error::Error
Dependencies
| ✅ - no_std
| ❌ - uses std
|
- ✅ bitflags
- ❌ cassowary - not updated since 2017, has no dependencies, probably safe to fork and do minimal changes to make it
no_std
-compatible, or do the same with @joshka's kasuari fork - ✅ compact_str
- ✅ indoc
- ✅ itertools
- ✅ lru
- ✅ strum
- ✅ thiserror
- ✅ unicode-segmentation
- ✅ unicode-truncate
- ✅ unicode-width
Optional dependencies
- ✅ anstyle
- ❌ document-features - only matters for docs
- ✅ palette
- ✅ serde
Tasks
✅ Core Tasks Stage 0 - preparations
- feat(no_std): remove redundant
std
usages inratatui-core
#1753 - chore(lint): add
std
instead ofcore
/alloc
lints toratatui-core
#1759
External tasks
✅ Core Tasks Stage 1 - no_std
ratatui-core
- build(deps): use kasuari instead of cassowary #1758
- refactor(no_std): Make usages of std explicit in ratatui-core. #1782
- feat(no_std)!: replace
Backend
'sio::Error
usages with associatedError
type #1778 - feat(no_std)!: option to disable layout cache for
no_std
compatibility #1795 - feat(no_std)!: make ratatui compatible with
#![no_std]
#1794 - feat(no_std)!: make
TestBackend::Error
Infallible
#1823
🏗️ Core Tasks Stage 2 - no_std
ratatui-widgets
& no_std
backends
- feat(no_std): remove redundant
std
usages inratatui-widgets
#1762 - chore(lint): add
std
instead ofcore
/alloc
lints toratatui-widgets
#1763 - feat(no_std): make
ratatui-widgets
no_std
#1779
External tasks
- feat(no_std): use
core
/alloc
instead ofstd
where possible j-g00da/mousefood#39 - chore(lint): add
std
instead ofcore
/alloc
lints j-g00da/mousefood#45 - Depend on
ratatui-core
instead ofratatui
j-g00da/mousefood#36 - Make mousefood work with
#![no_std]
j-g00da/mousefood#59
🏗️ Related bugfixes and other tasks
- feat(error)!: introduce
ratatui_core::error::Error
#1817 - fix(no_std): provide
f64
polyfills forno_std
compatibility #1840 - fix(layout-cache): import
NonZeroUsize
only whenlayout-cache
is enabled #1839 - fix(no_std): propagate
std
feature flag to dependencies #1838 - chore: move time to dev-dependencies #1835
- chore(widgets): move crossterm to dev-dependencies #1834
- fix(no_std): final patches needed for no_std #1833
- chore(breaking-changes): add details to
no_std
-related breaking changes #1828 - fix(layout): feature flag cache related types #1842
- feat(no_std): make the crate
no_std
-compatible joshka/line-clipping#1 - feat(no_std): option to disable
std
kasuari#16 - Add test for
*-unknown-none
build #1843 - build(deps): bump
kasuari
andline-clipping
#1844 - feat(no_std): make
ratatui-macros
no-std #1865