diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 56 |
1 files changed, 53 insertions, 3 deletions
@@ -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<Command>, + api_interface_definitions: Vec<APIInterfaceDefinition>, } 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<Item = Command>) -> Self + pub fn new( + commands: impl IntoIterator<Item = Command>, + api_interface_definitions: impl IntoIterator<Item = APIInterfaceDefinition>, + ) -> 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>("command") })?; - Ok(Self { commands }) + deserializer.skip_to_tag_start("feature")?; + + let api_interface_definitions = + deserializer.de_tag_list::<APIInterfaceDefinition>("feature")?; + + Ok(Self { + commands, + api_interface_definitions, + }) } } @@ -168,3 +190,31 @@ impl From<DeserializerError> 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()); + } + } + } + } +} |