Debian Codegraph @

third_party/rust/uniffi_udl/src/lib.rs

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 //! # Uniffi support for webidl syntax, typically from a .udl file, as described by weedle.
6 //!
7 //! This library is dedicated to parsing a string in a webidl syntax, as described by
8 //! weedle and with our own custom take on the attributes etc, pushing the boundaries
9 //! of that syntax to describe a uniffi `MetadataGroup`.
10 //!
11 //! The output of this module is consumed by uniffi_bindgen to generate stuff.
12
13 mod attributes;
14 mod collectors;
15 mod converters;
16 mod finder;
17 mod literal;
18 mod resolver;
19
20 use anyhow::Result;
21 use collectors::{InterfaceCollector, TypeCollector};
22 use uniffi_meta::Type;
23
24 /// The single entry-point to this module.
25 pub fn parse_udl(udl: &str, crate_name: &str) -> Result<uniffi_meta::MetadataGroup> {
26 Ok(InterfaceCollector::from_webidl(udl, crate_name)?.into())
27 }
28
29 #[cfg(test)]
30 mod test {
31 use super::*;
32
33 #[test]
34 fn test_group() {
35 const UDL: &str = r#"
36 namespace test{};
37 dictionary Empty {};
38 "#;
39 let group = parse_udl(UDL, "crate_name").unwrap();
40 assert_eq!(group.namespace.name, "test");
41 assert_eq!(group.items.len(), 1);
42 assert!(matches!(
43 group.items.into_iter().next().unwrap(),
44 uniffi_meta::Metadata::Record(r) if r.module_path == "crate_name" && r.name == "Empty" && r.fields.is_empty()
45 ));
46 }
47 }