golem_wasm_ast/metadata/
mod.rs

1// Copyright 2024-2025 Golem Cloud
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct Metadata {
17    pub name: Option<String>,
18    pub producers: Option<Producers>,
19}
20
21/// https://github.com/WebAssembly/tool-conventions/blob/main/ProducersSection.md
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct Producers {
24    pub fields: Vec<ProducersField>,
25}
26
27impl From<wasm_metadata::Producers> for Producers {
28    fn from(value: wasm_metadata::Producers) -> Self {
29        let mut fields = Vec::new();
30        for (name, field) in value.iter() {
31            let name = name.clone();
32            let mut values = Vec::new();
33            for (name, version) in field.iter() {
34                values.push(VersionedName {
35                    name: name.clone(),
36                    version: version.clone(),
37                });
38            }
39            fields.push(ProducersField { name, values });
40        }
41        Producers { fields }
42    }
43}
44
45#[derive(Debug, Clone, PartialEq, Eq)]
46pub struct ProducersField {
47    pub name: String,
48    pub values: Vec<VersionedName>,
49}
50
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct VersionedName {
53    pub name: String,
54    pub version: String,
55}