ruma_events/poll/unstable_start/
unstable_poll_answers_serde.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//! `Deserialize` helpers for unstable poll answers (MSC3381).

use serde::Deserialize;

use super::{UnstablePollAnswer, UnstablePollAnswers};
use crate::poll::start::{PollAnswers, PollAnswersError};

#[derive(Debug, Default, Deserialize)]
pub(crate) struct UnstablePollAnswersDeHelper(Vec<UnstablePollAnswer>);

impl TryFrom<UnstablePollAnswersDeHelper> for UnstablePollAnswers {
    type Error = PollAnswersError;

    fn try_from(helper: UnstablePollAnswersDeHelper) -> Result<Self, Self::Error> {
        let mut answers = helper.0;
        answers.truncate(PollAnswers::MAX_LENGTH);
        UnstablePollAnswers::try_from(answers)
    }
}