From 86f41e49f87764f9afd4be1d0d008a320dcfc331 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 26 Mar 2023 18:50:31 +0200 Subject: feat: add deserializing API interface definitions --- src/lib.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 68af8ae..4e33f8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,10 +26,12 @@ use std::io::Read; use quick_xml::events::BytesStart; +use crate::api_interface_definition::APIInterfaceDefinition; use crate::command::{Command, Error as CommandError}; use crate::deserialization::buffer_deserializer::BufferDeserializer; use crate::deserialization::{Deserialize, Deserializer, DeserializerError, IgnoreEnd}; +pub mod api_interface_definition; pub mod command; mod deserialization; @@ -45,6 +47,7 @@ const REGISTRY_TAG_NAME: &str = "registry"; pub struct Registry { commands: Vec, + api_interface_definitions: Vec, } impl Registry @@ -96,19 +99,30 @@ impl Registry /// # Note /// This will **NOT** use anything from the actual OpenGL registry. Use the /// [`Registry::retrieve`] method for that. - pub fn new(commands: impl IntoIterator) -> Self + pub fn new( + commands: impl IntoIterator, + api_interface_definitions: impl IntoIterator, + ) -> Self { Self { commands: commands.into_iter().collect(), + api_interface_definitions: api_interface_definitions.into_iter().collect(), } } - /// Returns the available commands. + /// Returns the commands. #[must_use] pub fn commands(&self) -> &[Command] { &self.commands } + + /// Returns the API interface definitions. + #[must_use] + pub fn api_interface_definitions(&self) -> &[APIInterfaceDefinition] + { + &self.api_interface_definitions + } } impl Deserialize for Registry @@ -127,7 +141,15 @@ impl Deserialize for Registry deserializer.de_tag_list::("command") })?; - Ok(Self { commands }) + deserializer.skip_to_tag_start("feature")?; + + let api_interface_definitions = + deserializer.de_tag_list::("feature")?; + + Ok(Self { + commands, + api_interface_definitions, + }) } } @@ -168,3 +190,31 @@ impl From for RegistryError #[derive(Debug, thiserror::Error)] #[error(transparent)] pub struct DeserializationError(#[from] DeserializerError); + +#[cfg(test)] +mod tests +{ + use super::*; + + #[test] + fn registry_works() + { + let registry = Registry::retrieve().expect("Expected Ok"); + + for api_interface_def in registry.api_interface_definitions() { + println!( + "{} - {}", + api_interface_def.api_name(), + api_interface_def.version() + ); + + println!("Removals:"); + + for removal in api_interface_def.removals() { + for feature in removal.features() { + println!(" {:?} - {}", feature.kind(), feature.name()); + } + } + } + } +} -- cgit v1.2.3-18-g5258