summaryrefslogtreecommitdiffstats
path: root/third_party/rust/wast/src/component/custom.rs
blob: b17a7fafb4d270d0121e6ee05b328898fb261a9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::annotation;
use crate::parser::{Parse, Parser, Result};
use crate::token::Span;

/// A custom section within a component.
#[derive(Debug)]
pub struct Custom<'a> {
    /// Where this `@custom` was defined.
    pub span: Span,

    /// Name of the custom section.
    pub name: &'a str,

    /// Payload of this custom section.
    pub data: Vec<&'a [u8]>,
}

impl<'a> Parse<'a> for Custom<'a> {
    fn parse(parser: Parser<'a>) -> Result<Self> {
        let span = parser.parse::<annotation::custom>()?.0;
        let name = parser.parse()?;
        let mut data = Vec::new();
        while !parser.is_empty() {
            data.push(parser.parse()?);
        }
        Ok(Self { span, name, data })
    }
}