Skip to content

Commit 746d002

Browse files
authored
Port bindings-doctests.sh into CI (#5155)
# Description of Changes Part of #4970. Doing this part in a separate PR because it turns out that this test was failing, so this PR also includes the fixes. # API and ABI breaking changes None # Expected complexity level and risk 1 # Testing CI passes (but only with the "code" changes). --------- Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
1 parent d79a769 commit 746d002

6 files changed

Lines changed: 15 additions & 27 deletions

File tree

crates/bindings/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ fn players_for_level(ctx: &AnonymousViewContext) -> Vec<PlayerAndLevel> {
618618
.player_level()
619619
.level()
620620
.filter(2u64)
621-
.map(|player| {
621+
.filter_map(|player| {
622622
ctx.db
623623
.player()
624624
.id()

crates/bindings/bindings-doctests.sh

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

crates/bindings/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ pub use spacetimedb_bindings_macro::settings;
365365
/// // The following line would panic, since we use `insert` rather than `try_insert`.
366366
/// // let result = ctx.db.country().insert(Country { code: "CN".into(), national_bird: "Blue Magpie".into() });
367367
///
368-
/// // If we wanted to *update* the row for Australia, we can use the `update` method of `UniqueIndex`.
369-
/// // The following line will succeed:
370-
/// ctx.db.country().code().update(Country {
368+
/// // If we wanted to replace the row for Australia, we can delete it and insert the new row.
369+
/// assert!(ctx.db.country().code().delete("AU".to_string()));
370+
/// ctx.db.country().insert(Country {
371371
/// code: "AU".into(), national_bird: "Australian Emu".into()
372372
/// });
373373
/// }
@@ -1118,7 +1118,7 @@ impl ReducerContext {
11181118
/// #[reducer]
11191119
/// fn generate_uuid_v4(ctx: &ReducerContext) -> Result<(), Box<dyn std::error::Error>> {
11201120
/// let uuid = ctx.new_uuid_v4()?;
1121-
/// log::info!(uuid);
1121+
/// log::info!("{uuid}");
11221122
/// Ok(())
11231123
/// }
11241124
/// # }
@@ -1140,7 +1140,7 @@ impl ReducerContext {
11401140
/// #[reducer]
11411141
/// fn generate_uuid_v7(ctx: &ReducerContext) -> Result<(), Box<dyn std::error::Error>> {
11421142
/// let uuid = ctx.new_uuid_v7()?;
1143-
/// log::info!(uuid);
1143+
/// log::info!("{uuid}");
11441144
/// Ok(())
11451145
/// }
11461146
/// # }

crates/bindings/src/rng.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ impl ReducerContext {
3030
///
3131
/// ```no_run
3232
/// # #[cfg(target_arch = "wasm32")] mod demo {
33-
/// use spacetimedb::{reducer, ReducerContext};
34-
/// use rand::Rng;
33+
/// use spacetimedb::{rand::Rng, reducer, ReducerContext};
3534
///
3635
/// #[spacetimedb::reducer]
3736
/// fn rng_demo(ctx: &spacetimedb::ReducerContext) {
@@ -40,7 +39,7 @@ impl ReducerContext {
4039
///
4140
/// // Or, cache locally for reuse:
4241
/// let mut rng = ctx.rng();
43-
/// let floats: Vec<f32> = rng.sample_iter(rand::distributions::Standard).collect();
42+
/// let floats: Vec<f32> = rng.sample_iter(spacetimedb::rand::distributions::Standard).collect();
4443
/// }
4544
/// # }
4645
/// ```

crates/bindings/src/table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ pub trait IndexIsPointed: Index {}
516516
///
517517
/// ```no_run
518518
/// # #[cfg(target_arch = "wasm32")] mod demo {
519-
/// use spacetimedb::{table, PointIndex, ReducerContext, DbContext};
519+
/// use spacetimedb::{table, DbContext, PointIndex, ReducerContext};
520520
///
521521
/// #[table(accessor = user,
522522
/// index(accessor = dogs_and_name, hash(columns = [dogs, name])))]
@@ -537,7 +537,7 @@ pub trait IndexIsPointed: Index {}
537537
///
538538
/// ```no_run
539539
/// # #[cfg(target_arch = "wasm32")] mod demo {
540-
/// use spacetimedb::{table, PointIndex, ReducerContext, DbContext};
540+
/// use spacetimedb::{table, DbContext, RangedIndex, ReducerContext};
541541
///
542542
/// #[table(accessor = user)]
543543
/// struct User {
@@ -548,7 +548,7 @@ pub trait IndexIsPointed: Index {}
548548
/// }
549549
///
550550
/// fn demo(ctx: &ReducerContext) {
551-
/// let by_dogs: PointIndex<_, (u64,), _> = ctx.db().user().dogs();
551+
/// let by_dogs: RangedIndex<_, (u64,), _> = ctx.db().user().dogs();
552552
/// }
553553
/// # }
554554
/// ```

tools/ci/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,10 @@ fn main() -> Result<()> {
616616
.dir("crates/bindings-csharp")
617617
.run()?;
618618
cmd!("pnpm", "lint").run()?;
619+
cmd!("cargo", "test", "--doc", "--target", "wasm32-unknown-unknown")
620+
.dir("crates/bindings")
621+
.run()?;
622+
cmd!("cargo", "test", "--doc").dir("crates/bindings").run()?;
619623
// `bindings` is the only crate we care strongly about documenting,
620624
// since we link to its docs.rs from our website.
621625
// We won't pass `--no-deps`, though,

0 commit comments

Comments
 (0)