Skip to content

Serde on the Builder? #126

Answered by Veetaha
rdong8 asked this question in Q&A
Sep 11, 2024 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

Yeah, I don't think bon fits this use case, because here you have a complex dynamic type state that should be represented manually.

I can suggest a couple of alternative approaches.

An improved "Second way" approach. In this case we don't need an enum of state. The order builder with Option fields already delivers enough state info:

struct OrderBuilder {
    item_id: Option<ItemId>,
    full_name: Option<Name>,
    address: Option<Address>,
    card_number: Option<CardNumber>,
    card_pin: Option<CardPin>,
}


fn update_state(message: String, mut order: OrderBuilder) -> Result<OrderBuilder> {
    match order {
        OrderBuilder { item_id: None, .. } => order.item_id = Some(message.parse(

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@rdong8
Comment options

@Veetaha
Comment options

Answer selected by rdong8
@rdong8
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants