Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bindings-macro/src/procedure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub(crate) fn procedure_impl(args: ProcedureArgs, original_function: &ItemFn) ->
}
};
impl #func_name {
fn invoke(__ctx: spacetimedb::ProcedureContext, __args: &[u8]) -> spacetimedb::ProcedureResult {
fn invoke(__ctx: &mut spacetimedb::ProcedureContext, __args: &[u8]) -> spacetimedb::ProcedureResult {
spacetimedb::rt::invoke_procedure(#func_name, __ctx, __args)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bindings-macro/src/reducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub(crate) fn reducer_impl(args: ReducerArgs, original_function: &ItemFn) -> syn
}
};
impl #func_name {
fn invoke(__ctx: spacetimedb::ReducerContext, __args: &[u8]) -> spacetimedb::ReducerResult {
fn invoke(__ctx: &spacetimedb::ReducerContext, __args: &[u8]) -> spacetimedb::ReducerResult {
spacetimedb::rt::invoke_reducer(#func_name, __ctx, __args)
}
}
Expand Down
18 changes: 9 additions & 9 deletions crates/bindings/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ impl<T> IntoVec<T> for Option<T> {
/// and otherwise the error is written into the fresh one returned.
pub fn invoke_reducer<'a, A: Args<'a>>(
reducer: impl Reducer<'a, A>,
ctx: ReducerContext,
ctx: &ReducerContext,
args: &'a [u8],
) -> Result<(), Box<str>> {
// Deserialize the arguments from a bsatn encoding.
let SerDeArgs(args) = bsatn::from_slice(args).expect("unable to decode args");

reducer.invoke(&ctx, args)
reducer.invoke(ctx, args)
}

#[cfg(feature = "unstable")]
pub fn invoke_procedure<'a, A: Args<'a>, Ret: IntoProcedureResult>(
procedure: impl Procedure<'a, A, Ret>,
mut ctx: ProcedureContext,
ctx: &mut ProcedureContext,
args: &'a [u8],
) -> ProcedureResult {
// Deserialize the arguments from a bsatn encoding.
let SerDeArgs(args) = bsatn::from_slice(args).expect("unable to decode args");

let res = procedure.invoke(&mut ctx, args);
let res = procedure.invoke(ctx, args);

res.to_result()
}
Expand Down Expand Up @@ -831,11 +831,11 @@ static DESCRIBERS: Mutex<Vec<Box<dyn DescriberFn>>> = Mutex::new(Vec::new());

/// A reducer function takes in `(ReducerContext, Args)`
/// and returns a result with a possible error message.
pub type ReducerFn = fn(ReducerContext, &[u8]) -> ReducerResult;
pub type ReducerFn = fn(&ReducerContext, &[u8]) -> ReducerResult;
static REDUCERS: OnceLock<Vec<ReducerFn>> = OnceLock::new();

#[cfg(feature = "unstable")]
pub type ProcedureFn = fn(ProcedureContext, &[u8]) -> ProcedureResult;
pub type ProcedureFn = fn(&mut ProcedureContext, &[u8]) -> ProcedureResult;
#[cfg(feature = "unstable")]
static PROCEDURES: OnceLock<Vec<ProcedureFn>> = OnceLock::new();

Expand Down Expand Up @@ -945,7 +945,7 @@ extern "C" fn __call_reducer__(
// Fetch reducer function.
let reducers = REDUCERS.get().unwrap();
// Dispatch to it with the arguments read.
let res = with_read_args(args, |args| reducers[id](ctx, args));
let res = with_read_args(args, |args| reducers[id](&ctx, args));
// Convert any error message to an error code and writes to the `error` sink.
convert_err_to_errno(res, error)
}
Expand Down Expand Up @@ -1037,13 +1037,13 @@ extern "C" fn __call_procedure__(
let timestamp = Timestamp::from_micros_since_unix_epoch(timestamp as i64);

// Assemble the `ProcedureContext`.
let ctx = ProcedureContext::new(sender, conn_id, timestamp);
let mut ctx = ProcedureContext::new(sender, conn_id, timestamp);

// Grab the list of procedures, which is populated by the preinit functions.
let procedures = PROCEDURES.get().unwrap();

// Deserialize the args and pass them to the actual procedure.
let res = with_read_args(args, |args| procedures[id](ctx, args));
let res = with_read_args(args, |args| procedures[id](&mut ctx, args));

// Write the result bytes to the `result_sink`.
write_to_sink(result_sink, &res);
Expand Down
13 changes: 6 additions & 7 deletions crates/sats/src/typespace.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::any::TypeId;
use std::ops::{Index, IndexMut};
use std::rc::Rc;
use std::sync::Arc;

use crate::algebraic_type::AlgebraicType;
use crate::algebraic_type_ref::AlgebraicTypeRef;
use crate::WithTypespace;
use core::any::TypeId;
use core::ops::{Index, IndexMut};
use ethnum::{i256, u256};
use smallvec::SmallVec;
use std::rc::Rc;
use std::sync::Arc;

/// An error that occurs when attempting to resolve a type.
#[derive(thiserror::Error, Debug, PartialOrd, Ord, PartialEq, Eq)]
Expand Down Expand Up @@ -316,8 +317,6 @@ pub trait SpacetimeType {
fn make_type<S: TypespaceBuilder>(typespace: &mut S) -> AlgebraicType;
}

use ethnum::{i256, u256};
use smallvec::SmallVec;
pub use spacetimedb_bindings_macro::SpacetimeType;

/// A trait for types that can build a [`Typespace`].
Expand Down
Loading