Rust
The Rivet Rust client provides a way to connect to and interact with actors from Rust applications.
Quickstart
Create a new Rust project
Create a new Rust project:
Add dependencies
Add Rivet client & related dependencies to your project:
Define your actor schema and implementation. Create a new file for your actor:
// actors/counter.ts
import { Actor } from '@rivetkit/actor';
export interface CounterState {
count: number;
}
export class CounterActor extends Actor<CounterState> {
getInitialState() {
return { count: 0 };
}
increment() {
this.setState({ count: this.state.count + 1 });
}
decrement() {
this.setState({ count: this.state.count - 1 });
}
}
Create your client
Modify src/main.rs
to connect to your actor:
Start the Rivet development studio to test your actors locally:
npx rivetkit dev
This will start the local development server and open the Rivet Studio in your browser where you can interact with your actors.
Run your client
In a separate terminal, run your client code:
You should see output like:
Run it again to see the state update.
Deploy your actors to production:
npx rivetkit deploy
This will build and deploy your actors to the Rivet cloud platform. Make sure you're logged in with rivetkit login
.
Next Steps
- 1Explore the Actors documentation to learn more about building stateful services
- 2Check out Integrations to connect with your favorite frameworks
- 3Join our Discord community for support and discussions