| 1 | use crate::annotation; |
| 2 | use crate::parser::{Parse, Parser, Result}; |
| 3 | use crate::token::Span; |
| 4 | |
| 5 | /// A custom section within a component. |
| 6 | #[derive (Debug)] |
| 7 | pub struct Custom<'a> { |
| 8 | /// Where this `@custom` was defined. |
| 9 | pub span: Span, |
| 10 | |
| 11 | /// Name of the custom section. |
| 12 | pub name: &'a str, |
| 13 | |
| 14 | /// Payload of this custom section. |
| 15 | pub data: Vec<&'a [u8]>, |
| 16 | } |
| 17 | |
| 18 | impl<'a> Parse<'a> for Custom<'a> { |
| 19 | fn parse(parser: Parser<'a>) -> Result<Self> { |
| 20 | let span: Span = parser.parse::<annotation::custom>()?.0; |
| 21 | let name: &'a str = parser.parse()?; |
| 22 | let mut data: Vec<&'a [u8]> = Vec::new(); |
| 23 | while !parser.is_empty() { |
| 24 | data.push(parser.parse()?); |
| 25 | } |
| 26 | Ok(Self { span, name, data }) |
| 27 | } |
| 28 | } |
| 29 | |