Skip to content

Commit b862066

Browse files
committed
Switch to NonZeroU128 for NodeIDs
This handles clients who use UUIDs for widget IDs.
1 parent 8585ae7 commit b862066

File tree

6 files changed

+37
-36
lines changed

6 files changed

+37
-36
lines changed

common/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,9 @@ pub enum StringEncoding {
569569
Utf16,
570570
}
571571

572-
// This is NonZeroU64 because we regularly store Option<NodeId>.
573-
pub type NodeIdContent = std::num::NonZeroU64;
572+
// This is NonZeroU128 because we regularly store Option<NodeId>.
573+
// 128-bit to handle UUIDs.
574+
pub type NodeIdContent = std::num::NonZeroU128;
574575

575576
/// The stable identity of a node, unique within the node's tree.
576577
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]

consumer/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@ mod tests {
2323
use accesskit::{
2424
ActionHandler, ActionRequest, Node, NodeId, Role, StringEncoding, Tree, TreeId, TreeUpdate,
2525
};
26-
use std::num::NonZeroU64;
26+
use std::num::NonZeroU128;
2727
use std::sync::Arc;
2828

29-
pub const ROOT_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(1) });
30-
pub const PARAGRAPH_0_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(2) });
31-
pub const STATIC_TEXT_0_0_IGNORED_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(3) });
32-
pub const PARAGRAPH_1_IGNORED_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(4) });
33-
pub const STATIC_TEXT_1_0_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(5) });
34-
pub const PARAGRAPH_2_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(6) });
35-
pub const STATIC_TEXT_2_0_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(7) });
36-
pub const PARAGRAPH_3_IGNORED_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(8) });
29+
pub const ROOT_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(1) });
30+
pub const PARAGRAPH_0_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(2) });
31+
pub const STATIC_TEXT_0_0_IGNORED_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(3) });
32+
pub const PARAGRAPH_1_IGNORED_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(4) });
33+
pub const STATIC_TEXT_1_0_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(5) });
34+
pub const PARAGRAPH_2_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(6) });
35+
pub const STATIC_TEXT_2_0_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(7) });
36+
pub const PARAGRAPH_3_IGNORED_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(8) });
3737
pub const EMPTY_CONTAINER_3_0_IGNORED_ID: NodeId =
38-
NodeId(unsafe { NonZeroU64::new_unchecked(9) });
39-
pub const LINK_3_1_IGNORED_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(10) });
40-
pub const STATIC_TEXT_3_1_0_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(11) });
41-
pub const BUTTON_3_2_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(12) });
38+
NodeId(unsafe { NonZeroU128::new_unchecked(9) });
39+
pub const LINK_3_1_IGNORED_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(10) });
40+
pub const STATIC_TEXT_3_1_0_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(11) });
41+
pub const BUTTON_3_2_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(12) });
4242
pub const EMPTY_CONTAINER_3_3_IGNORED_ID: NodeId =
43-
NodeId(unsafe { NonZeroU64::new_unchecked(13) });
43+
NodeId(unsafe { NonZeroU128::new_unchecked(13) });
4444

4545
pub struct NullActionHandler;
4646

consumer/src/node.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,16 +539,16 @@ impl Node<'_> {
539539
mod tests {
540540
use accesskit::kurbo::{Point, Rect};
541541
use accesskit::{Node, NodeId, Role, StringEncoding, Tree, TreeId, TreeUpdate};
542-
use std::num::NonZeroU64;
542+
use std::num::NonZeroU128;
543543

544544
use crate::tests::*;
545545

546546
const TREE_ID: &str = "test_tree";
547-
const NODE_ID_1: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(1) });
548-
const NODE_ID_2: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(2) });
549-
const NODE_ID_3: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(3) });
550-
const NODE_ID_4: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(4) });
551-
const NODE_ID_5: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(5) });
547+
const NODE_ID_1: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(1) });
548+
const NODE_ID_2: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(2) });
549+
const NODE_ID_3: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(3) });
550+
const NODE_ID_4: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(4) });
551+
const NODE_ID_5: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(5) });
552552

553553
#[test]
554554
fn parent_and_index() {

consumer/src/tree.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,14 @@ impl Tree {
351351
#[cfg(test)]
352352
mod tests {
353353
use accesskit::{Node, NodeId, Role, StringEncoding, Tree, TreeId, TreeUpdate};
354-
use std::num::NonZeroU64;
354+
use std::num::NonZeroU128;
355355

356356
use crate::tests::NullActionHandler;
357357

358358
const TREE_ID: &str = "test_tree";
359-
const NODE_ID_1: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(1) });
360-
const NODE_ID_2: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(2) });
361-
const NODE_ID_3: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(3) });
359+
const NODE_ID_1: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(1) });
360+
const NODE_ID_2: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(2) });
361+
const NODE_ID_3: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(3) });
362362

363363
#[test]
364364
fn init_tree_with_root_node() {

platforms/windows/examples/hello_world.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Based on the create_window sample in windows-samples-rs.
22

3-
use std::{cell::RefCell, convert::TryInto, mem::drop, num::NonZeroU64, rc::Rc};
3+
use std::{cell::RefCell, convert::TryInto, mem::drop, num::NonZeroU128, rc::Rc};
44

55
use accesskit::kurbo::Rect;
66
use accesskit::{
@@ -65,9 +65,9 @@ lazy_static! {
6565

6666
const WINDOW_TITLE: &str = "Hello world";
6767

68-
const WINDOW_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(1) });
69-
const BUTTON_1_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(2) });
70-
const BUTTON_2_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(3) });
68+
const WINDOW_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(1) });
69+
const BUTTON_1_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(2) });
70+
const BUTTON_2_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(3) });
7171
const INITIAL_FOCUS: NodeId = BUTTON_1_ID;
7272

7373
const BUTTON_1_RECT: Rect = Rect {
@@ -301,7 +301,7 @@ extern "system" fn wndproc(window: HWND, message: u32, wparam: WPARAM, lparam: L
301301
_ => unsafe { DefWindowProcW(window, message, wparam, lparam) },
302302
},
303303
SET_FOCUS_MSG => {
304-
if let Some(id) = lparam.0.try_into().ok().map(NonZeroU64::new).flatten() {
304+
if let Some(id) = lparam.0.try_into().ok().map(NonZeroU128::new).flatten() {
305305
let id = NodeId(id);
306306
if id == BUTTON_1_ID || id == BUTTON_2_ID {
307307
let window_state = unsafe { &*get_window_state(window) };
@@ -315,7 +315,7 @@ extern "system" fn wndproc(window: HWND, message: u32, wparam: WPARAM, lparam: L
315315
LRESULT(0)
316316
}
317317
DO_DEFAULT_ACTION_MSG => {
318-
if let Some(id) = lparam.0.try_into().ok().map(NonZeroU64::new).flatten() {
318+
if let Some(id) = lparam.0.try_into().ok().map(NonZeroU128::new).flatten() {
319319
let id = NodeId(id);
320320
if id == BUTTON_1_ID || id == BUTTON_2_ID {
321321
let window_state = unsafe { &*get_window_state(window) };

platforms/windows/src/tests/simple.rs

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

6-
use std::{convert::TryInto, num::NonZeroU64};
6+
use std::{convert::TryInto, num::NonZeroU128};
77

88
use accesskit::{
99
ActionHandler, ActionRequest, Node, NodeId, Role, StringEncoding, Tree, TreeId, TreeUpdate,
@@ -14,9 +14,9 @@ use super::*;
1414

1515
const WINDOW_TITLE: &str = "Simple test";
1616

17-
const WINDOW_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(1) });
18-
const BUTTON_1_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(2) });
19-
const BUTTON_2_ID: NodeId = NodeId(unsafe { NonZeroU64::new_unchecked(3) });
17+
const WINDOW_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(1) });
18+
const BUTTON_1_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(2) });
19+
const BUTTON_2_ID: NodeId = NodeId(unsafe { NonZeroU128::new_unchecked(3) });
2020

2121
fn make_button(id: NodeId, name: &str) -> Node {
2222
Node {

0 commit comments

Comments
 (0)