Skip to content

Commit cdbfee1

Browse files
anakrishCopilot
andcommitted
refactor(tests,docs): migrate tests; CHANGELOG and migration guide; v0.11.0
Migrates tests/ to the Object/Set API. Deletes dead src/tests/common.rs (was not declared as a module). Bumps version 0.10.1 -> 0.11.0 to reflect the breaking change to Value::Object / Value::Set payload types. Cargo.lock files for the 9 binding crates regenerate against the new version. Adds: - CHANGELOG.md "Breaking Changes" entry summarizing the payload and accessor signature change. - docs/migration-collections.md with per-pattern migration recipes, iteration-order contract notes, and notes on the deprecated / renamed surface. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4ba94b8 commit cdbfee1

11 files changed

Lines changed: 143 additions & 205 deletions

File tree

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Breaking
10+
11+
- `Value::Object` payload changed from `Rc<BTreeMap<Value, Value>>` to
12+
`Rc<Object>`. `Value::Set` payload changed from `Rc<BTreeSet<Value>>` to
13+
`Rc<Set>`. The new types live in `regorus::collections` and expose the same
14+
shape (`get`, `insert`, `iter`, `contains_key`, etc.). Most call sites
15+
compile unchanged; pattern-match bindings see `&Rc<Object>` / `&Rc<Set>`
16+
instead of `&Rc<BTreeMap>` / `&Rc<BTreeSet>`. See
17+
[`docs/migration-collections.md`](docs/migration-collections.md).
18+
- `Value::as_object`, `Value::as_object_mut`, `Value::as_set`,
19+
`Value::as_set_mut` return types changed from `&BTreeMap` / `&BTreeSet`
20+
(etc.) to `&Object` / `&Set` (etc.). Method names are unchanged.
21+
- `Object` / `Set` iteration: `iter()` / `keys()` are
22+
implementation-defined order (today: sorted, because storage is
23+
`BTreeMap`/`BTreeSet`; future variants may differ). Use `iter_sorted()` /
24+
`keys_sorted()` for canonical/user-visible output. Both execution backends
25+
(interpreter, RVM) use `iter()` / `keys()` for evaluation iteration to
26+
preserve dual-path equivalence.
27+
928
## [0.10.1](https://github.com/microsoft/regorus/compare/regorus-v0.10.0...regorus-v0.10.1) - 2026-05-22
1029

1130
### Fixed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ members = [
88
[package]
99
name = "regorus"
1010
description = "A fast, lightweight Rego (OPA policy language) interpreter"
11-
version = "0.10.1"
11+
version = "0.11.0"
1212
edition = "2021"
1313
license = "MIT AND Apache-2.0 AND BSD-3-Clause"
1414
repository = "https://github.com/microsoft/regorus"

bindings/ffi/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/java/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/python/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/wasm/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/migration-collections.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Migration: `Value::Object` / `Value::Set` payload swap (0.11.0)
2+
3+
In `0.11.0` the inner storage of `Value::Object` and `Value::Set` was hidden
4+
behind two opaque types in the new `regorus::collections` module:
5+
6+
| Old | New |
7+
| -------------------------------------- | ------------------------- |
8+
| `Value::Object(Rc<BTreeMap<Value,V>>)` | `Value::Object(Rc<Object>)` |
9+
| `Value::Set(Rc<BTreeSet<Value>>)` | `Value::Set(Rc<Set>)` |
10+
11+
`Object` mirrors the shape of `BTreeMap<Value, Value>` and `Set` mirrors
12+
`BTreeSet<Value>`, so most call sites compile unchanged. This document covers
13+
the few that don't, plus iteration-order semantics that callers should be
14+
aware of even when their code still compiles.
15+
16+
## Source-of-truth: the public surface
17+
18+
```rust
19+
use regorus::collections::{Object, Set};
20+
21+
let mut o = Object::new();
22+
o.insert(Value::from("k"), Value::from(1));
23+
assert!(o.contains_key(&Value::from("k")));
24+
let v: Value = o.into(); // From<Object> for Value
25+
```
26+
27+
## Per-pattern recipes
28+
29+
### `as_object()` / `as_object_mut()` / `as_set()` / `as_set_mut()`
30+
31+
**Method names unchanged.** Only the return type changed:
32+
33+
```rust
34+
// Before
35+
let m: &BTreeMap<Value, Value> = v.as_object()?;
36+
37+
// After
38+
let m: &Object = v.as_object()?;
39+
m.get(&key); // same
40+
m.iter(); // same
41+
m.contains_key(&key); // same
42+
```
43+
44+
The `_mut` siblings still go through `Rc::make_mut` (copy-on-write) under the
45+
hood — mutating one `Value` clone does not affect aliased holders.
46+
47+
### Constructing a `Value::Object` from a literal
48+
49+
```rust
50+
// Before
51+
Value::Object(Rc::new(BTreeMap::from_iter(pairs)))
52+
53+
// After
54+
Object::from_iter(pairs).into()
55+
// or, equivalently:
56+
Object::from_iter(pairs).into_value()
57+
```
58+
59+
`Set` mirrors this:
60+
61+
```rust
62+
// Before
63+
Value::Set(Rc::new(BTreeSet::from_iter(items)))
64+
65+
// After
66+
Set::from_iter(items).into()
67+
```
68+
69+
### Pattern-matching `Value::Object(rc)` / `Value::Set(rc)`
70+
71+
`rc` is now `&Rc<Object>` / `&Rc<Set>` instead of `&Rc<BTreeMap>` /
72+
`&Rc<BTreeSet>`. All the methods you used on the inner collection
73+
(`len`, `is_empty`, `get`, `contains_key`, `iter`, `keys`, `values`,
74+
`insert`, `remove`, `retain`, `clear`, `append`, `extend`, `Index` by key,
75+
`IntoIterator`) exist on `Object` / `Set` with identical signatures and
76+
semantics.
77+
78+
The one collection-specific surface that disappeared is the `BTreeMap::entry`
79+
API. Use `Object::get_or_insert_with(key, default)` for the common
80+
entry-pattern shape (single-probe insert-if-absent).
81+
82+
## Iteration-order semantics (read this)
83+
84+
Iteration is split into **two methods** that mirror std's `HashMap` vs
85+
`BTreeMap` convention:
86+
87+
| Method | Order | Use for |
88+
| -------------------------------------------- | ------------------------------------ | ------------------------------------ |
89+
| `iter()` / `keys()` / `values()` | implementation-defined | Rego evaluation iteration |
90+
| `iter_sorted()` / `keys_sorted()` | sorted by `Value::Ord` | canonical / user-visible output |
91+
92+
Today the BTree-backed storage means `iter()` happens to return sorted order,
93+
but **callers must not depend on that**. A future hash-backed variant could
94+
change it.
95+
96+
**Both execution backends (interpreter and RVM) use `iter()` / `keys()` for
97+
evaluation iteration**, to preserve dual-path equivalence. Sites that produce
98+
canonical output (`Serialize`, `Debug`, `to_printable`, `Set::first` /
99+
`Set::last`) use `iter_sorted()` explicitly.
100+
101+
If you call `iter()` and rely on the iteration being sorted, switch to
102+
`iter_sorted()`.
103+
104+
## Things that did not change
105+
106+
- Equality, ordering, and hashing of `Object` / `Set` are unchanged.
107+
- `Serialize` / `Deserialize` for `Value::Object` / `Value::Set` produce the
108+
same JSON as before.
109+
- `Rc::make_mut` copy-on-write semantics for `Value::as_object_mut` /
110+
`Value::as_set_mut` are unchanged.
111+
- The set algebra surface (`union`, `intersection`, `difference`,
112+
`symmetric_difference`, `is_subset`, `is_superset`, `is_disjoint`) is
113+
preserved.

src/tests/common.rs

Lines changed: 0 additions & 188 deletions
This file was deleted.

0 commit comments

Comments
 (0)