-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Rust module documentation #2050
base: master
Are you sure you want to change the base?
Conversation
6137dc2
to
1d89177
Compare
68c8c19
to
0f1c3df
Compare
More docs One more patch More table docs More docs Denser sats comments Move comments More doc rewriting Substantial rewrite of main doc slug More links and emphasis Hmm Document macros inline in the bindings crate to make links better Fix some errors in rust module bindings docs + work on schedule documentation Table macro docs polish A day of writing
09b3a03
to
1256125
Compare
There are still a number of doctest failures that need to be fixed, and some warnings in upstream crates of |
@@ -0,0 +1,517 @@ | |||
# SpacetimeDB Rust Module Library |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend reviewing starting here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great stuff, thanks!
but *are* resolved when compiled by Rustdoc. | ||
--> | ||
|
||
[SpacetimeDB](https://spacetimedb.com/) allows using the Rust language to write server-side applications called **modules**. Modules run **inside** a SQL database. They have direct access to database tables, and expose public functions called **reducers** that can be invoked over the network. Clients connect directly to the database to read data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[SpacetimeDB](https://spacetimedb.com/) allows using the Rust language to write server-side applications called **modules**. Modules run **inside** a SQL database. They have direct access to database tables, and expose public functions called **reducers** that can be invoked over the network. Clients connect directly to the database to read data. | |
[SpacetimeDB](https://spacetimedb.com/) allows using the Rust language to write server-side applications called **modules**. Modules run inside a relational database. They have direct access to database tables, and expose public functions called **reducers** that can be invoked over the network. Clients connect directly to the database to read data. |
The defining feature of our DBs are not their SQL handling; modules do not interact with their DBs via SQL.
"inside" is not a vocab word here, and so should not use the same formatting as "modules" and "reducers." I also don't think it needs to be emphasized.
|
||
Rust modules are written with the the Rust Module Library (this crate). They are built using [cargo](https://doc.rust-lang.org/cargo/) and deployed using the [`spacetime` CLI tool](https://spacetimedb.com/install). Rust modules can import any Rust [crate](https://crates.io/) that supports being compiled to WebAssembly. | ||
|
||
(Note: Rust can also be used to write **clients** of SpacetimeDB databases, but this requires using a completely different library, the SpacetimeDB Rust Client SDK. See the documentation on [clients] for more information.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this link work? There's no header or anchor in this file for it to go to, but when I click on it in the GitHub Markdown viewer, somehow it sends me to https://spacetimedb.com/docs/#client .
Created new database with identity: <hex string> | ||
``` | ||
|
||
This hex string is the [`Identity`] of the created database. It distinguishes the created database from the other databases running on the SpacetimeDB network. It is used when administering the module, for example using the [`spacetime logs <DATABASE_IDENTITY>`](#the-log-crate) command. You should save it to a text file so that you can remember it. <!-- TODO: is there a CLI command that says "list all Identities running this version of a module?" --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a CLI command that says "list all Identities running this version of a module?
Nope.
spacetime publish | ||
``` | ||
|
||
When you publish your module, a database will be created with the requested tables, and the module will be installed inside it. | ||
|
||
The output of `spacetime publish` will end with a line: | ||
```text | ||
Created new database with identity: <hex string> | ||
``` | ||
|
||
This hex string is the [`Identity`] of the created database. It distinguishes the created database from the other databases running on the SpacetimeDB network. It is used when administering the module, for example using the [`spacetime logs <DATABASE_IDENTITY>`](#the-log-crate) command. You should save it to a text file so that you can remember it. <!-- TODO: is there a CLI command that says "list all Identities running this version of a module?" --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend telling readers to name their DBs. "Make sure to write down this hex string!" is pretty terrible compared to "give it a fun name you'll remember! Also, it has this hex string. Anywhere you use the name, you can use the hex string too."
|
||
Under the hood, SpacetimeDB modules are WebAssembly modules that import a [specific WebAssembly ABI](https://spacetimedb.com/docs/webassembly-abi) and export a small number of special functions. This is automatically configured when you add the `spacetime` crate as a dependency of your application. | ||
|
||
The SpacetimeDB host is an application that hosts SpacetimeDB databases. It is [source available](https://github.com/clockworklabs/SpacetimeDB). You can run your own host, or you can upload your module to the public SpacetimeDB network. <!-- TODO: want a link to some dashboard for the public network. --> The network will create a database for you and install your module in it to serve client requests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SpacetimeDB host is an application that hosts SpacetimeDB databases. It is [source available](https://github.com/clockworklabs/SpacetimeDB). You can run your own host, or you can upload your module to the public SpacetimeDB network. <!-- TODO: want a link to some dashboard for the public network. --> The network will create a database for you and install your module in it to serve client requests. | |
The SpacetimeDB host is an application that hosts SpacetimeDB databases. [Its source code is available](https://github.com/clockworklabs/SpacetimeDB) under [the Business Source License with an Additional Use Grant](https://github.com/clockworklabs/SpacetimeDB/blob/master/LICENSE.txt). You can run your own host, or you can upload your module to the public SpacetimeDB network. <!-- TODO: want a link to some dashboard for the public network. --> The network will create a database for you and install your module in it to serve client requests. |
@@ -542,7 +542,7 @@ pub trait DeserializeSeed<'de> { | |||
use crate::de::impls::BorrowedSliceVisitor; | |||
pub use spacetimedb_bindings_macro::Deserialize; | |||
|
|||
/// A **datastructure** that can be deserialized from any data format supported by SATS. | |||
/// A **data structure** that can be deserialized from any data format supported by the SpacetimeDB Algebraic Type System. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emphasis is weird and ugly here.
/// Do not manually implement this trait unless you know what you are doing. | ||
/// Incorrect implementations are safe, but can result in data loss. | ||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same note about this warning.
/// | ||
/// Deriving this trait also derives [`Serialize`](crate::ser::Serialize), [`Deserialize`](crate::de::Deserialize), | ||
/// and [`Debug`](std::fmt::Debug). (There are currently no trait bounds on `SpacetimeType` documenting this fact.) | ||
/// These traits are used to convert Rust data structures to other formats, suitable for storing on disk or passing over the network. `Debug` is simply for debugging convenience. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// These traits are used to convert Rust data structures to other formats, suitable for storing on disk or passing over the network. `Debug` is simply for debugging convenience. | |
/// `Serialize` and `Deserialize` are used to convert Rust data structures to other formats, suitable for storing on disk or passing over the network. `Debug` is simply for debugging convenience. |
/// and [`Debug`](std::fmt::Debug). (There are currently no trait bounds on `SpacetimeType` documenting this fact.) | ||
/// These traits are used to convert Rust data structures to other formats, suitable for storing on disk or passing over the network. `Debug` is simply for debugging convenience. | ||
/// | ||
/// Any Rust type implementing `SpacetimeType` can be used in table and reducer declarations. A derive macro is provided, and can be used on both structs and enums: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you be more specific? I believe we don't allow tuple structs. I'm not sure whether or not we allow unit structs. I think on enums we only allow unit variants and single-element tuple variants, not struct variants or n-tuple variants. I could be wrong though; you should check.
/// | ||
/// (Storing collections in rows of a database table is a form of [denormalization](https://en.wikipedia.org/wiki/Denormalization).) | ||
/// | ||
/// Do not manually implement this trait unless you are VERY sure you know what you're doing. Incorrect implementations can result in data loss! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing about the warning here.
Description of Changes
While I'm rewriting the reference, I figured I'd do this as well.
Expected complexity level and risk
0
Testing
Added doctests