aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-03-26 18:50:31 +0200
committerHampusM <hampus@hampusmat.com>2023-03-26 18:50:31 +0200
commit86f41e49f87764f9afd4be1d0d008a320dcfc331 (patch)
tree3e7cf94bcecd42ccf2f1e8eb9928a377d4fdb1bd /src/lib.rs
parentc8e5944d697b33738c7ba01694dde5e360470043 (diff)
feat: add deserializing API interface definitions
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs56
1 files changed, 53 insertions, 3 deletions
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<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());
+ }
+ }
+ }
+ }
+}