-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposition for a stable API #338
Comments
Making |
Ah, yes! I see now. Making |
How about: impl<Extensions, Extension = String> Registry<Extensions> where
Extension: AsRef<str>,
Extensions: IntoIterator<Item = Extension>,
{
pub fn new(api: Api, version: (u8, u8): &str, profile: Profile, extensions: Extensions, fallbacks: Fallbacks) -> Registry<Extensions>;
pub fn write_bindings(self, &mut output, generator) -> io::Result<()>;
} Then: Registry::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::All)
.write_bindings(&mut output, generators::Global)
.unwrap(); |
As discussed in #338, this means that users no longer need to depend on khronos_api.
As discussed in #338, this means that users no longer need to depend on khronos_api.
@tomaka How happy are you with the current API on master? I would like this to work, but I cant get the type inference to work when no extensions are specified: impl Registry {
pub fn new<Exts, Ext = String>(api: Api, version: (u8, u8), profile: Profile, fallbacks: Fallbacks, extensions: Exts) -> Registry where
Ext: AsRef<str>,
Exts: IntoIterator<Item = Extension>;
pub fn write_bindings<W, G>(&self, generator: G, output: &mut W) -> io::Result<()> where
G: Generator,
W: io::Write;
} Might be an issue with combining default type params and trait constraints... |
The issues with the default type parameters might be related to what @nikomatsakis was talking about in this comment: rust-lang/rfcs#1196 (comment). One solution, if we really wanted an // no extensions
RegistryBuilder::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::All)
.build()
.write_bindings(&mut output, generators::Global)
.unwrap();
// extensions
RegistryBuilder::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::All)
.with_extensions(["GL_ARB_debug_output"])
.build()
.write_bindings(&mut output, generators::Global)
.unwrap(); I reckon that is ugly and confusing though. I think we should just call it a day and accept an Registry::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::All, ["GL_ARB_debug_output"])
.write_bindings(&mut output, generators::Global)
.unwrap(); |
Craziest idea yet: Have a build script for Registry::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::All, [Extension::GL_ARB_debug_output]) No more stringly typed stuff! It's almost like a hacky form of type providers! /jokeyjoke |
The current API is pretty crappy, so here is my proposition to have a clean API and release some kind of non-work-in-progress version of the gl_generator.
registry
andgenerators
modules from the outside of the crate.generate
.As far as I know, nobody has written an external generator yet, so I don't think it's a problem to remove this possibility.
The signature of
generate
would be like this:khronos_api
(major point IMO)api
Vec<String>
or a&[&str]
.version
andprofile
are still strings as their content are peeked directly at the XML files. Not using an enum means that we won't have to do any modification when a new version of OpenGL is released.The text was updated successfully, but these errors were encountered: