Skip to content

Conversation

joshua-spacetime
Copy link
Collaborator

@joshua-spacetime joshua-spacetime commented Oct 17, 2025

Description of Changes

Adds the #[view] procedural macro and module describers for views.

#[view(public)]
fn player(ctx: &ViewContext) -> Vec<Player> {
    ctx.db.player().identity().find(ctx.sender).into_iter().collect()
}

#[view(public)]
fn player(ctx: &AnonymousViewContext, level: u32) -> Vec<Player> {
    ctx.db.player().level().filter(level).collect()
}

Note, this deviates from the proposal in that views may only return Vec<T> or Option<T>. They can't return an arbitrary SpacetimeType.

API and ABI breaking changes

None

Expected complexity level and risk

2

Testing

  • Negative compile tests
  • Negative publish (module validation) tests
  • Test system tables are updated accurately

@bfops bfops added the release-any To be landed in any release window label Oct 20, 2025
@Centril Centril self-requested a review October 20, 2025 17:37
Comment on lines +143 to +147
type Invoke = spacetimedb::rt::ReducerFn;
const NAME: &'static str = #reducer_name;
#(const LIFECYCLE: Option<spacetimedb::rt::LifecycleReducer> = Some(#lifecycle);)*
const ARG_NAMES: &'static [Option<&'static str>] = &[#(#opt_arg_names),*];
const INVOKE: spacetimedb::rt::ReducerFn = #func_name::invoke;
const INVOKE: Self::Invoke = #func_name::invoke;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is worth mentioning in the PR description. In some sense it is breaking, but not in a way we promise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what sense exactly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this were to be implemented manually, we would break such users. We haven't promised such stability, but it might be worth mentioning nonetheless.

/// ctx.db.player().level().filter(level).collect()
/// }
/// # }
/// ```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an example of a join and an example of a part of a table?

@joshua-spacetime joshua-spacetime changed the base branch from joshua/module-defs-for-views to master October 21, 2025 03:27
@joshua-spacetime joshua-spacetime changed the base branch from master to joshua/module-defs-for-views October 21, 2025 03:28
@joshua-spacetime joshua-spacetime force-pushed the joshua/view-macro-bindings branch from 73ed5f9 to 6a8d021 Compare October 21, 2025 03:34
@joshua-spacetime joshua-spacetime changed the base branch from joshua/module-defs-for-views to master October 21, 2025 03:35
@joshua-spacetime joshua-spacetime removed the request for review from cloutiertyler October 21, 2025 03:36
@joshua-spacetime joshua-spacetime force-pushed the joshua/view-macro-bindings branch 6 times, most recently from 2ecd24d to 8a11196 Compare October 22, 2025 00:34
@joshua-spacetime joshua-spacetime force-pushed the joshua/view-macro-bindings branch from 8a11196 to 6eebf6e Compare October 22, 2025 06:46
@joshua-spacetime joshua-spacetime force-pushed the joshua/view-macro-bindings branch from 6eebf6e to b52a38a Compare October 22, 2025 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-any To be landed in any release window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants