Skip to content
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

add SharedObjectContext example to cart_object.rs #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions rust/tutorials/tour-of-restate-rust/src/part4/cart_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub(crate) trait CartObject {
async fn checkout() -> Result<bool, HandlerError>;
#[name = "expireTicket"]
async fn expire_ticket(ticket_id: String) -> Result<(), HandlerError>;

#[shared]
async fn list() -> Result<String, HandlerError>;
}

pub struct CartObjectImpl;
Expand Down Expand Up @@ -100,4 +103,18 @@ impl CartObject for CartObjectImpl {

Ok(())
}

async fn list(
&self,
ctx: SharedObjectContext<'_>
) -> Result<String, HandlerError> {
let mut tickets = ctx
.get::<Json<HashSet<String>>>("tickets")
.await?
.unwrap_or_default()
.into_inner();

let tickets_vec: Vec<String> = tickets.into_iter().collect();
Ok(tickets_vec.join(","))
}
}