Skip to content

Commit f25d03a

Browse files
authored
feat: Make the consumer crate no-std (#471)
1 parent 40ad828 commit f25d03a

File tree

8 files changed

+41
-17
lines changed

8 files changed

+41
-17
lines changed

Cargo.lock

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

consumer/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ rust-version.workspace = true
1313

1414
[dependencies]
1515
accesskit = { version = "0.17.0", path = "../common" }
16-
immutable-chunkmap = "2.0.5"
16+
hashbrown = { version = "0.15", default-features = false, features = ["default-hasher"] }
17+
immutable-chunkmap = "2.0.6"

consumer/src/iterators.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Use of this source code is governed by a BSD-style license that can be
99
// found in the LICENSE.chromium file.
1010

11-
use std::iter::FusedIterator;
11+
use core::iter::FusedIterator;
1212

1313
use accesskit::NodeId;
1414

@@ -435,7 +435,7 @@ impl<'a, Filter: Fn(&Node) -> FilterResult> FusedIterator for FilteredChildren<'
435435
pub(crate) enum LabelledBy<'a, Filter: Fn(&Node) -> FilterResult> {
436436
FromDescendants(FilteredChildren<'a, Filter>),
437437
Explicit {
438-
ids: std::slice::Iter<'a, NodeId>,
438+
ids: core::slice::Iter<'a, NodeId>,
439439
tree_state: &'a TreeState,
440440
},
441441
}
@@ -477,6 +477,7 @@ impl<'a, Filter: Fn(&Node) -> FilterResult> FusedIterator for LabelledBy<'a, Fil
477477
mod tests {
478478
use crate::tests::*;
479479
use accesskit::NodeId;
480+
use alloc::vec::Vec;
480481

481482
#[test]
482483
fn following_siblings() {

consumer/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// the LICENSE-APACHE file) or the MIT license (found in
44
// the LICENSE-MIT file), at your option.
55

6+
#![no_std]
7+
8+
extern crate alloc;
9+
610
pub(crate) mod tree;
711
pub use tree::{ChangeHandler as TreeChangeHandler, State as TreeState, Tree};
812

@@ -23,6 +27,7 @@ pub use text::{
2327
#[cfg(test)]
2428
mod tests {
2529
use accesskit::{Affine, Node, NodeId, Rect, Role, Tree, TreeUpdate, Vec2};
30+
use alloc::vec;
2631

2732
use crate::FilterResult;
2833

consumer/src/node.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
// Use of this source code is governed by a BSD-style license that can be
99
// found in the LICENSE.chromium file.
1010

11-
use std::{iter::FusedIterator, sync::Arc};
12-
1311
use accesskit::{
1412
Action, Affine, FrozenNode as NodeData, Live, NodeId, Orientation, Point, Rect, Role,
1513
TextSelection, Toggled,
1614
};
15+
use alloc::{
16+
string::{String, ToString},
17+
sync::Arc,
18+
vec::Vec,
19+
};
20+
use core::iter::FusedIterator;
1721

1822
use crate::filters::FilterResult;
1923
use crate::iterators::{
@@ -665,6 +669,7 @@ impl<'a> Node<'a> {
665669
#[cfg(test)]
666670
mod tests {
667671
use accesskit::{Node, NodeId, Point, Rect, Role, Tree, TreeUpdate};
672+
use alloc::vec;
668673

669674
use crate::tests::*;
670675

consumer/src/text.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use accesskit::{
77
NodeId, Point, Rect, Role, TextDirection, TextPosition as WeakPosition, TextSelection,
88
};
9-
use std::{cmp::Ordering, iter::FusedIterator};
9+
use alloc::{string::String, vec::Vec};
10+
use core::{cmp::Ordering, iter::FusedIterator};
1011

1112
use crate::{FilterResult, Node, TreeState};
1213

@@ -488,7 +489,7 @@ pub struct Range<'a> {
488489
impl<'a> Range<'a> {
489490
fn new(node: Node<'a>, mut start: InnerPosition<'a>, mut end: InnerPosition<'a>) -> Self {
490491
if start.comparable(&node) > end.comparable(&node) {
491-
std::mem::swap(&mut start, &mut end);
492+
core::mem::swap(&mut start, &mut end);
492493
}
493494
Self { node, start, end }
494495
}
@@ -1089,6 +1090,7 @@ impl<'a> Node<'a> {
10891090
#[cfg(test)]
10901091
mod tests {
10911092
use accesskit::{NodeId, Point, Rect, TextSelection};
1093+
use alloc::vec;
10921094

10931095
// This is based on an actual tree produced by egui.
10941096
fn main_multiline_tree(selection: Option<TextSelection>) -> crate::Tree {

consumer/src/tree.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
// the LICENSE-MIT file), at your option.
55

66
use accesskit::{FrozenNode as NodeData, NodeId, Tree as TreeData, TreeUpdate};
7+
use alloc::{format, string::String, sync::Arc, vec, vec::Vec};
8+
use hashbrown::{HashMap, HashSet};
79
use immutable_chunkmap::map::MapM as ChunkMap;
8-
use std::{
9-
collections::{HashMap, HashSet},
10-
sync::Arc,
11-
};
1210

1311
use crate::node::{Node, NodeState, ParentAndIndex};
1412

@@ -103,7 +101,7 @@ impl State {
103101
} else {
104102
pending_children.insert(*child_id, parent_and_index);
105103
}
106-
seen_child_ids.insert(child_id);
104+
seen_child_ids.insert(*child_id);
107105
}
108106

109107
if let Some(node_state) = self.nodes.get_mut_cow(&node_id) {
@@ -147,14 +145,14 @@ impl State {
147145
self.is_host_focused = is_host_focused;
148146

149147
if !orphans.is_empty() {
150-
let mut to_remove = HashSet::new();
148+
let mut to_remove = Vec::new();
151149

152150
fn traverse_orphan(
153151
nodes: &ChunkMap<NodeId, NodeState>,
154-
to_remove: &mut HashSet<NodeId>,
152+
to_remove: &mut Vec<NodeId>,
155153
id: NodeId,
156154
) {
157-
to_remove.insert(id);
155+
to_remove.push(id);
158156
let node = nodes.get(&id).unwrap();
159157
for child_id in node.data.children().iter() {
160158
traverse_orphan(nodes, to_remove, *child_id);
@@ -367,6 +365,7 @@ fn short_node_list<'a>(nodes: impl ExactSizeIterator<Item = &'a NodeId>) -> Stri
367365
#[cfg(test)]
368366
mod tests {
369367
use accesskit::{Node, NodeId, Role, Tree, TreeUpdate};
368+
use alloc::vec;
370369

371370
#[test]
372371
fn init_tree_with_root_node() {

deny.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ allow = [
2121
"BSD-3-Clause",
2222
"ISC",
2323
"MIT",
24+
"Zlib",
2425
]
2526
deny = []
2627
copyleft = "warn"

0 commit comments

Comments
 (0)