Skip to content

Commit 3301a99

Browse files
committed
[release/v1.7.0]: Revert "Add macro bindings for views (#3429)"
This reverts commit 0d325b2.
1 parent 58f3c31 commit 3301a99

File tree

12 files changed

+47
-1275
lines changed

12 files changed

+47
-1275
lines changed

crates/bindings-macro/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ mod reducer;
1212
mod sats;
1313
mod table;
1414
mod util;
15-
mod view;
1615

1716
use proc_macro::TokenStream as StdTokenStream;
1817
use proc_macro2::TokenStream;
@@ -113,14 +112,6 @@ pub fn reducer(args: StdTokenStream, item: StdTokenStream) -> StdTokenStream {
113112
})
114113
}
115114

116-
#[proc_macro_attribute]
117-
pub fn view(args: StdTokenStream, item: StdTokenStream) -> StdTokenStream {
118-
cvt_attr::<ItemFn>(args, item, quote!(), |args, original_function| {
119-
let args = view::ViewArgs::parse(args)?;
120-
view::view_impl(args, original_function)
121-
})
122-
}
123-
124115
/// It turns out to be shockingly difficult to construct an [`Attribute`].
125116
/// That type is not [`Parse`], instead having two distinct methods
126117
/// for parsing "inner" vs "outer" attributes.

crates/bindings-macro/src/reducer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,11 @@ pub(crate) fn reducer_impl(args: ReducerArgs, original_function: &ItemFn) -> syn
139139
}
140140
}
141141
#[automatically_derived]
142-
impl spacetimedb::rt::FnInfo for #func_name {
143-
type Invoke = spacetimedb::rt::ReducerFn;
142+
impl spacetimedb::rt::ReducerInfo for #func_name {
144143
const NAME: &'static str = #reducer_name;
145144
#(const LIFECYCLE: Option<spacetimedb::rt::LifecycleReducer> = Some(#lifecycle);)*
146145
const ARG_NAMES: &'static [Option<&'static str>] = &[#(#opt_arg_names),*];
147-
const INVOKE: Self::Invoke = #func_name::invoke;
146+
const INVOKE: spacetimedb::rt::ReducerFn = #func_name::invoke;
148147
}
149148
})
150149
}

crates/bindings-macro/src/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R
821821
let reducer = &sched.reducer;
822822
let scheduled_at_id = scheduled_at_column.index;
823823
let desc = quote!(spacetimedb::table::ScheduleDesc {
824-
reducer_name: <#reducer as spacetimedb::rt::FnInfo>::NAME,
824+
reducer_name: <#reducer as spacetimedb::rt::ReducerInfo>::NAME,
825825
scheduled_at_column: #scheduled_at_id,
826826
});
827827

crates/bindings-macro/src/view.rs

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

crates/bindings/src/lib.rs

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -666,133 +666,6 @@ pub use spacetimedb_bindings_macro::table;
666666
#[doc(inline)]
667667
pub use spacetimedb_bindings_macro::reducer;
668668

669-
/// Marks a function as a spacetimedb view.
670-
///
671-
/// A view is a function with read-only access to the database.
672-
///
673-
/// The first argument of a view is always a [`&ViewContext`] or [`&AnonymousViewContext`].
674-
/// The former can only read from the database whereas latter can also access info about the caller.
675-
///
676-
/// After this, a view can take any number of arguments just like reducers.
677-
/// These arguments must implement the [`SpacetimeType`], [`Serialize`], and [`Deserialize`] traits.
678-
/// All of these traits can be derived at once by marking a type with `#[derive(SpacetimeType)]`.
679-
///
680-
/// Views return `Vec<T>` or `Option<T>` where `T` is a `SpacetimeType`.
681-
///
682-
/// ```no_run
683-
/// # mod demo {
684-
/// use spacetimedb::{view, table, AnonymousViewContext, SpacetimeType, ViewContext};
685-
/// use spacetimedb_lib::Identity;
686-
///
687-
/// #[table(name = player)]
688-
/// struct Player {
689-
/// #[auto_inc]
690-
/// #[primary_key]
691-
/// id: u64,
692-
///
693-
/// #[unique]
694-
/// identity: Identity,
695-
///
696-
/// #[index(btree)]
697-
/// level: u32,
698-
/// }
699-
///
700-
/// impl Player {
701-
/// fn merge(self, location: Location) -> PlayerAndLocation {
702-
/// PlayerAndLocation {
703-
/// player_id: self.id,
704-
/// level: self.level,
705-
/// x: location.x,
706-
/// y: location.y,
707-
/// }
708-
/// }
709-
/// }
710-
///
711-
/// #[derive(SpacetimeType)]
712-
/// struct PlayerId {
713-
/// id: u64,
714-
/// }
715-
///
716-
/// #[table(name = location, index(name = coordinates, btree(columns = [x, y])))]
717-
/// struct Location {
718-
/// #[unique]
719-
/// player_id: u64,
720-
/// x: u64,
721-
/// y: u64,
722-
/// }
723-
///
724-
/// #[derive(SpacetimeType)]
725-
/// struct PlayerAndLocation {
726-
/// player_id: u64,
727-
/// level: u32,
728-
/// x: u64,
729-
/// y: u64,
730-
/// }
731-
///
732-
/// // A view that selects at most one row from a table
733-
/// #[view(public)]
734-
/// fn my_player(ctx: &ViewContext) -> Option<Player> {
735-
/// ctx.db.player().identity().find(ctx.sender)
736-
/// }
737-
///
738-
/// // An example of column projection
739-
/// #[view(public)]
740-
/// fn my_player_id(ctx: &ViewContext) -> Option<PlayerId> {
741-
/// ctx.db.player().identity().find(ctx.sender).map(|Player { id, .. }| PlayerId { id })
742-
/// }
743-
///
744-
/// // An example of a parameterized view
745-
/// #[view(public)]
746-
/// fn players_at_level(ctx: &AnonymousViewContext, level: u32) -> Vec<Player> {
747-
/// ctx.db.player().level().filter(level).collect()
748-
/// }
749-
///
750-
/// // An example that is analogous to a semijoin in sql
751-
/// #[view(public)]
752-
/// fn players_at_coordinates(ctx: &AnonymousViewContext, x: u64, y: u64) -> Vec<Player> {
753-
/// ctx
754-
/// .db
755-
/// .location()
756-
/// .coordinates()
757-
/// .filter((x, y))
758-
/// .filter_map(|location| ctx.db.player().id().find(location.player_id))
759-
/// .collect()
760-
/// }
761-
///
762-
/// // An example of a join that combines fields from two different tables
763-
/// #[view(public)]
764-
/// fn players_with_coordinates(ctx: &AnonymousViewContext, x: u64, y: u64) -> Vec<PlayerAndLocation> {
765-
/// ctx
766-
/// .db
767-
/// .location()
768-
/// .coordinates()
769-
/// .filter((x, y))
770-
/// .filter_map(|location| ctx
771-
/// .db
772-
/// .player()
773-
/// .id()
774-
/// .find(location.player_id)
775-
/// .map(|player| player.merge(location))
776-
/// )
777-
/// .collect()
778-
/// }
779-
/// # }
780-
/// ```
781-
///
782-
/// Just like reducers, views are limited in their ability to interact with the outside world.
783-
/// They have no access to any network or filesystem interfaces.
784-
/// Calling methods from [`std::io`], [`std::net`], or [`std::fs`] will result in runtime errors.
785-
///
786-
/// Views are callable by reducers and other views simply by passing their `ViewContext`..
787-
/// This is a regular function call.
788-
/// The callee will run within the caller's transaction.
789-
///
790-
///
791-
/// [`&ViewContext`]: `ViewContext`
792-
/// [`&AnonymousViewContext`]: `AnonymousViewContext`
793-
#[doc(inline)]
794-
pub use spacetimedb_bindings_macro::view;
795-
796669
/// One of two possible types that can be passed as the first argument to a `#[view]`.
797670
/// The other is [`ViewContext`].
798671
/// Use this type if the view does not depend on the caller's identity.

0 commit comments

Comments
 (0)