Glium: trouble finding what type I'm using / How to figure out libraries


#1

I’m in the middle of constructing some code for drawing… https://bpaste.net/show/e546df01dee4

I need create_quad to not only return the vertex buffer but also the index buffer. I figured out already that F needs to be of trait Facade, but only because I looked at the signature of glium::VertexBuffer::new.
Now, I don’t know what type it should return for the index buffer.
let display = glium::glutin::WindowBuilder::new().build_glium().unwrap();
What type is display?
let mut target = display.draw();
What type is target?
And most importantly… how do I go about finding out how to use a library, and in particular what types stuff should be and what methods they have?


#2

There might be a more elegant way for the first question (I’m totally new at this), but I’ve been assigning bogus types to the variable and letting the compiler complain about the difference. So the code would be:

let display: String = glium::glutin::WindowBuilder::new().build_glium().unwrap();

Build and then enjoy the error messages.

As far as the inflection stuff goes, I’m terribly interested in the answer to this question, too. Maybe using a debugger?


#3

Here is your code returning the indexbuffer. You should probably make it generic.

Display

You can find this information in the function signatures in the Glium docs.

build_glium() returns a Facade , as you found out, which is a trait. The implementors for Facade are:

  • GlutinFacade (glium::backend::glutin_backend::GlutinFacade)
  • Rc<Context>

You are most likely looking at GlutinFacade for your application.

Target

Same approach; for the draw() method you can see in its signature that it returns a Frame


#4

@fcourchesne Do you know if there’s any way to get this information without reading the source code? I’m all for reading source code, but it would be nice to have some sort of inspection capabilities too.


#5

@bitgrinder LLDB or GDB will give you that information. The information will not always be trivial to understand. I find reading the source code or docs much clearer to find this type of information. There is also the method of asking the compiler to tell you what it expects by assigning a bogus type to the function as previously mentioned.

The following is how you would get the variable types for my previous answer.

Method using GDB

cargo build (build in debug mode, you will require symbols to debug --release not work well)
rust-gdb target/debug/answer (assuming the project is named answer)
b main.rs:54 (set breakpoints)
b main.rs:59
run (run the program, up to first breakpoint at line 54)

print display (print variable “display”)

$1 = GlutinFacade = {context = Rcglium::context::Context = {ptr = Shared<alloc::rc::RcBoxglium::context::Context> = {pointer = NonZero<*const alloc::rc::RcBoxglium::context::Context> = {0x7ffff0e69c00}, _marker = PhantomData<alloc::rc::RcBoxglium::context::Context>}}, backend = Rc<core::option::Option<core::cell::RefCell<alloc::rc::Rcglium::backend::glutin_backend::GlutinWindowBackend>>> = {ptr = Shared<alloc::rc::RcBox<core::option::Option<core::cell::RefCell<alloc::rc::Rcglium::backend::glutin_backend::GlutinWindowBackend>>>> = {pointer = NonZero<*const alloc::rc::RcBox<core::option::Option<core::cell::RefCell<alloc::rc::Rcglium::backend::glutin_backend::GlutinWindowBackend>>>> = {0x7ffff6d02560}, _marker = PhantomData<alloc::rc::RcBox<core::option::Option<core::cell::RefCell<alloc::rc::Rcglium::backend::glutin_backend::GlutinWindowBackend>>>>}}}

continue (now continue the program up to breakpoint at line 59)
print target (print variable “target”)

$2 = Frame = {context = Rcglium::context::Context = {ptr = Shared<alloc::rc::RcBoxglium::context::Context> = {pointer = NonZero<*const alloc::rc::RcBoxglium::context::Context> = {0x7ffff0e69c00}, _marker = PhantomData<alloc::rc::RcBoxglium::context::Context>}}, dimensions = {0x400, 0x300}, destroyed = 0x0}

Hope this helps.