ruma_events/poll/unstable_start/
unstable_poll_answers_serde.rs

1//! `Deserialize` helpers for unstable poll answers (MSC3381).
2
3use serde::Deserialize;
4
5use super::{UnstablePollAnswer, UnstablePollAnswers};
6use crate::poll::start::{PollAnswers, PollAnswersError};
7
8#[derive(Debug, Default, Deserialize)]
9pub(crate) struct UnstablePollAnswersDeHelper(Vec<UnstablePollAnswer>);
10
11impl TryFrom<UnstablePollAnswersDeHelper> for UnstablePollAnswers {
12    type Error = PollAnswersError;
13
14    fn try_from(helper: UnstablePollAnswersDeHelper) -> Result<Self, Self::Error> {
15        let mut answers = helper.0;
16        answers.truncate(PollAnswers::MAX_LENGTH);
17        UnstablePollAnswers::try_from(answers)
18    }
19}