Skip to content

Commit

Permalink
feat: Make the consumer crate no-std
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcampbell committed Nov 3, 2024
1 parent 9634fc2 commit 2d4aabc
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 17 deletions.
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion consumer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ rust-version.workspace = true

[dependencies]
accesskit = { version = "0.17.0", path = "../common" }
immutable-chunkmap = "2.0.5"
hashbrown = { version = "0.15", default-features = false, features = ["default-hasher"] }
immutable-chunkmap = "2.0.6"
5 changes: 3 additions & 2 deletions consumer/src/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.

use std::iter::FusedIterator;
use core::iter::FusedIterator;

use accesskit::NodeId;

Expand Down Expand Up @@ -435,7 +435,7 @@ impl<'a, Filter: Fn(&Node) -> FilterResult> FusedIterator for FilteredChildren<'
pub(crate) enum LabelledBy<'a, Filter: Fn(&Node) -> FilterResult> {
FromDescendants(FilteredChildren<'a, Filter>),
Explicit {
ids: std::slice::Iter<'a, NodeId>,
ids: core::slice::Iter<'a, NodeId>,
tree_state: &'a TreeState,
},
}
Expand Down Expand Up @@ -477,6 +477,7 @@ impl<'a, Filter: Fn(&Node) -> FilterResult> FusedIterator for LabelledBy<'a, Fil
mod tests {
use crate::tests::*;
use accesskit::NodeId;
use alloc::vec::Vec;

#[test]
fn following_siblings() {
Expand Down
5 changes: 5 additions & 0 deletions consumer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

#![no_std]

extern crate alloc;

pub(crate) mod tree;
pub use tree::{ChangeHandler as TreeChangeHandler, State as TreeState, Tree};

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

use crate::FilterResult;

Expand Down
9 changes: 7 additions & 2 deletions consumer/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.

use std::{iter::FusedIterator, sync::Arc};

use accesskit::{
Action, Affine, FrozenNode as NodeData, Live, NodeId, Orientation, Point, Rect, Role,
TextSelection, Toggled,
};
use alloc::{
string::{String, ToString},
sync::Arc,
vec::Vec,
};
use core::iter::FusedIterator;

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

use crate::tests::*;

Expand Down
6 changes: 4 additions & 2 deletions consumer/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
use accesskit::{
NodeId, Point, Rect, Role, TextDirection, TextPosition as WeakPosition, TextSelection,
};
use std::{cmp::Ordering, iter::FusedIterator};
use alloc::{string::String, vec::Vec};
use core::{cmp::Ordering, iter::FusedIterator};

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

Expand Down Expand Up @@ -488,7 +489,7 @@ pub struct Range<'a> {
impl<'a> Range<'a> {
fn new(node: Node<'a>, mut start: InnerPosition<'a>, mut end: InnerPosition<'a>) -> Self {
if start.comparable(&node) > end.comparable(&node) {
std::mem::swap(&mut start, &mut end);
core::mem::swap(&mut start, &mut end);
}
Self { node, start, end }
}
Expand Down Expand Up @@ -1089,6 +1090,7 @@ impl<'a> Node<'a> {
#[cfg(test)]
mod tests {
use accesskit::{NodeId, Point, Rect, TextSelection};
use alloc::vec;

// This is based on an actual tree produced by egui.
fn main_multiline_tree(selection: Option<TextSelection>) -> crate::Tree {
Expand Down
15 changes: 7 additions & 8 deletions consumer/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
// the LICENSE-MIT file), at your option.

use accesskit::{FrozenNode as NodeData, NodeId, Tree as TreeData, TreeUpdate};
use alloc::{format, string::String, sync::Arc, vec, vec::Vec};
use hashbrown::{HashMap, HashSet};
use immutable_chunkmap::map::MapM as ChunkMap;
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};

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

Expand Down Expand Up @@ -103,7 +101,7 @@ impl State {
} else {
pending_children.insert(*child_id, parent_and_index);
}
seen_child_ids.insert(child_id);
seen_child_ids.insert(*child_id);
}

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

if !orphans.is_empty() {
let mut to_remove = HashSet::new();
let mut to_remove = Vec::new();

fn traverse_orphan(
nodes: &ChunkMap<NodeId, NodeState>,
to_remove: &mut HashSet<NodeId>,
to_remove: &mut Vec<NodeId>,
id: NodeId,
) {
to_remove.insert(id);
to_remove.push(id);
let node = nodes.get(&id).unwrap();
for child_id in node.data.children().iter() {
traverse_orphan(nodes, to_remove, *child_id);
Expand Down Expand Up @@ -367,6 +365,7 @@ fn short_node_list<'a>(nodes: impl ExactSizeIterator<Item = &'a NodeId>) -> Stri
#[cfg(test)]
mod tests {
use accesskit::{Node, NodeId, Role, Tree, TreeUpdate};
use alloc::vec;

#[test]
fn init_tree_with_root_node() {
Expand Down

0 comments on commit 2d4aabc

Please sign in to comment.