Skip to content

Commit af4d3f3

Browse files
authored
Make new Uuid type Filterable (#3991)
# Description of Changes `Uuid` addad in the last update is not filterable even though it is `Copy` and (imo) obviously _very_ suited to filter. Promote it to a special `FilterableValue` in the same way as `Identity` and adjust the docs. # API and ABI breaking changes None # Expected complexity level and risk 1. Only copies the same strategy as `Identity` which is also a newtype wrapper around a integer like `Uuid` # Testing Tested on my project. After the change: <img width="586" height="298" alt="image" src="https://github.com/user-attachments/assets/98e97c16-906b-4e66-b132-676ece40462e" /> Before the change: <img width="1495" height="547" alt="image" src="https://github.com/user-attachments/assets/da74e49a-1dbd-43ae-9b13-39dcc39c81dc" /> You can also test this yourself when adding: `spacetimedb = { version = "1.11.2", git = "https://github.com/kistz/SpacetimeDB.git", branch = "uuid-as-filter" }` to your cargo.toml project - [x] Tested before and after. Before it was a compiler error afterwards not.
1 parent 011c2fd commit af4d3f3

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

crates/bindings/tests/ui/tables.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ error[E0277]: `&'a Alpha` cannot appear as an argument to an index filtering ope
121121
--> tests/ui/tables.rs:32:33
122122
|
123123
32 | ctx.db.delta().compound_a().find(Alpha { beta: 0 });
124-
| ^^^^ should be an integer type, `bool`, `String`, `&str`, `Identity`, `ConnectionId`, `Hash` or a no-payload enum which derives `SpacetimeType`, not `&'a Alpha`
124+
| ^^^^ should be an integer type, `bool`, `String`, `&str`, `Identity`, `Uuid`, `ConnectionId`, `Hash` or a no-payload enum which derives `SpacetimeType`, not `&'a Alpha`
125125
|
126126
= help: the trait `for<'a> FilterableValue` is not implemented for `&'a Alpha`
127-
= note: The allowed set of types are limited to integers, bool, strings, `Identity`, `ConnectionId`, `Hash` and no-payload enums which derive `SpacetimeType`,
127+
= note: The allowed set of types are limited to integers, bool, strings, `Identity`, `Uuid`, `ConnectionId`, `Hash` and no-payload enums which derive `SpacetimeType`,
128128
= help: the following other types implement trait `FilterableValue`:
129129
&ConnectionId
130130
&Identity

crates/lib/src/filterable_value.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{ConnectionId, Identity};
1+
use crate::{ConnectionId, Identity, Uuid};
22
use core::ops;
33
use spacetimedb_sats::bsatn;
44
use spacetimedb_sats::{hash::Hash, i256, u256, Serialize};
@@ -16,6 +16,7 @@ use spacetimedb_sats::{hash::Hash, i256, u256, Serialize};
1616
/// - [`bool`].
1717
/// - [`String`], which is also filterable with `&str`.
1818
/// - [`Identity`].
19+
/// - [`Uuid`].
1920
/// - [`ConnectionId`].
2021
/// - [`Hash`](struct@Hash).
2122
/// - No-payload enums annotated with `#[derive(SpacetimeType)]`.
@@ -47,8 +48,8 @@ use spacetimedb_sats::{hash::Hash, i256, u256, Serialize};
4748
// E.g. `&str: FilterableValue<Column = String>` is desirable.
4849
#[diagnostic::on_unimplemented(
4950
message = "`{Self}` cannot appear as an argument to an index filtering operation",
50-
label = "should be an integer type, `bool`, `String`, `&str`, `Identity`, `ConnectionId`, `Hash` or a no-payload enum which derives `SpacetimeType`, not `{Self}`",
51-
note = "The allowed set of types are limited to integers, bool, strings, `Identity`, `ConnectionId`, `Hash` and no-payload enums which derive `SpacetimeType`,"
51+
label = "should be an integer type, `bool`, `String`, `&str`, `Identity`, `Uuid`, `ConnectionId`, `Hash` or a no-payload enum which derives `SpacetimeType`, not `{Self}`",
52+
note = "The allowed set of types are limited to integers, bool, strings, `Identity`, `Uuid`, `ConnectionId`, `Hash` and no-payload enums which derive `SpacetimeType`,"
5253
)]
5354
pub trait FilterableValue: Serialize + Private {
5455
type Column;
@@ -104,6 +105,7 @@ impl_filterable_value! {
104105
&str => String,
105106

106107
Identity: Copy,
108+
Uuid: Copy,
107109
ConnectionId: Copy,
108110
Hash: Copy,
109111

0 commit comments

Comments
 (0)