Skip to content

Commit c354643

Browse files
committed
Make TryInsertError static
1 parent 9510103 commit c354643

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

crates/bindings-macro/src/lib.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -958,15 +958,15 @@ fn table_impl(mut args: TableArgs, mut item: MutItem<syn::DeriveInput>) -> syn::
958958
let field_types = fields.iter().map(|f| f.ty).collect::<Vec<_>>();
959959

960960
let tabletype_impl = quote! {
961-
impl spacetimedb::Table for #tablehandle_ident<'_> {
961+
impl spacetimedb::Table for #tablehandle_ident {
962962
type Row = #row_type;
963963

964964
type UniqueConstraintViolation = #unique_err;
965965
type AutoIncOverflow = #autoinc_err;
966966

967967
#integrate_generated_columns
968968
}
969-
impl spacetimedb::table::TableInternal for #tablehandle_ident<'_> {
969+
impl spacetimedb::table::TableInternal for #tablehandle_ident {
970970
const TABLE_NAME: &'static str = #table_name;
971971
// the default value if not specified is Private
972972
#(const TABLE_ACCESS: spacetimedb::table::TableAccess = #table_access;)*
@@ -985,7 +985,7 @@ fn table_impl(mut args: TableArgs, mut item: MutItem<syn::DeriveInput>) -> syn::
985985
let describe_table_func = quote! {
986986
#[export_name = #register_describer_symbol]
987987
extern "C" fn __register_describer() {
988-
spacetimedb::rt::register_table::<#tablehandle_ident<'static>>()
988+
spacetimedb::rt::register_table::<#tablehandle_ident>()
989989
}
990990
};
991991

@@ -1027,22 +1027,21 @@ fn table_impl(mut args: TableArgs, mut item: MutItem<syn::DeriveInput>) -> syn::
10271027
let trait_def = quote_spanned! {table_ident.span()=>
10281028
#[allow(non_camel_case_types, dead_code)]
10291029
#vis trait #table_ident {
1030-
fn #table_ident(&self) -> #row_type_to_table<'_>;
1030+
fn #table_ident(&self) -> &#row_type_to_table;
10311031
}
10321032
impl #table_ident for spacetimedb::Local {
1033-
fn #table_ident(&self) -> #row_type_to_table<'_> {
1033+
fn #table_ident(&self) -> &#row_type_to_table {
10341034
#[allow(non_camel_case_types)]
1035-
type #tablehandle_ident<'a> = #row_type_to_table<'a>;
1036-
#tablehandle_ident { _local: ::core::marker::PhantomData }
1035+
type #tablehandle_ident = #row_type_to_table;
1036+
&#tablehandle_ident {}
10371037
}
10381038
}
10391039
};
10401040

10411041
let tablehandle_def = quote! {
10421042
#[allow(non_camel_case_types)]
1043-
#vis struct #tablehandle_ident<'a> {
1044-
_local: ::core::marker::PhantomData<&'a spacetimedb::Local>,
1045-
}
1043+
#[non_exhaustive]
1044+
#vis struct #tablehandle_ident {}
10461045
};
10471046

10481047
let emission = quote! {
@@ -1060,10 +1059,10 @@ fn table_impl(mut args: TableArgs, mut item: MutItem<syn::DeriveInput>) -> syn::
10601059
#tablehandle_def
10611060

10621061
impl spacetimedb::table::__MapRowTypeToTable for #row_type {
1063-
type Table<'a> = #tablehandle_ident<'a>;
1062+
type Table = #tablehandle_ident;
10641063
}
10651064

1066-
impl<'a> #tablehandle_ident<'a> {
1065+
impl #tablehandle_ident {
10671066
#(#unique_field_accessors)*
10681067
#(#index_accessors)*
10691068
}

crates/bindings/src/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub enum IndexAlgo<'a> {
145145

146146
#[doc(hidden)]
147147
pub trait __MapRowTypeToTable {
148-
type Table<'a>: Table;
148+
type Table: Table;
149149
}
150150

151151
/// A UNIQUE constraint violation on a table was attempted.

modules/rust-wasm-test/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ pub struct TestD {
2929

3030
// uses internal apis that should not be used by user code
3131
#[allow(dead_code)] // false positive
32-
const fn get_table_access<T: spacetimedb::table::__MapRowTypeToTable>() -> TableAccess {
33-
<T::Table<'static> as spacetimedb::table::TableInternal>::TABLE_ACCESS
32+
const fn get_table_access<Tbl: spacetimedb::Table>(_: impl Fn(&spacetimedb::Local) -> &Tbl + Copy) -> TableAccess {
33+
<Tbl as spacetimedb::table::TableInternal>::TABLE_ACCESS
3434
}
3535

3636
// This table was specified as public.
37-
const _: () = assert!(matches!(get_table_access::<TestD>(), TableAccess::Public));
37+
const _: () = assert!(matches!(get_table_access(test_d::test_d), TableAccess::Public));
3838

3939
#[spacetimedb::table(name = test_e)]
4040
#[derive(Debug)]
@@ -55,7 +55,7 @@ pub enum TestF {
5555
}
5656

5757
// // All tables are private by default.
58-
const _: () = assert!(matches!(get_table_access::<TestE>(), TableAccess::Private));
58+
const _: () = assert!(matches!(get_table_access(test_e::test_e), TableAccess::Private));
5959

6060
#[spacetimedb::table(name = private)]
6161
pub struct Private {
@@ -69,7 +69,7 @@ pub struct Point {
6969
}
7070

7171
// It is redundant, but we can explicitly specify a table as private.
72-
const _: () = assert!(matches!(get_table_access::<Point>(), TableAccess::Private));
72+
const _: () = assert!(matches!(get_table_access(points::points), TableAccess::Private));
7373

7474
// Test we can compile multiple constraints
7575
#[spacetimedb::table(name = pk_multi_identity)]

smoketests/tests/auto_inc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def do_test_autoinc(self, int_ty):
7272
7373
#[spacetimedb::reducer]
7474
pub fn add_new_$KEY_TY(ctx: &ReducerContext, name: String) -> Result<(), Box<dyn Error>> {
75-
let value = ctx.db.person_$KEY_TY().insert(Person_$KEY_TY { key_col: 0, name });
75+
let value = ctx.db.person_$KEY_TY().try_insert(Person_$KEY_TY { key_col: 0, name })?;
7676
println!("Assigned Value: {} -> {}", value.key_col, value.name);
7777
Ok(())
7878
}

0 commit comments

Comments
 (0)