Hello,
I'm playing with glium, trying to create small drawing framework. It seems that I cannot move forward without interior mutability. I have created very reduced project, which does nothing useful, just to narrow the problem. I would very appreciate any help on how to properly use Rc<RefCellglium::Display> in the code.
The error is:
error[E0277]: the trait bound std::cell::Ref<'_, glium::Display>: glium::backend::Facade
is not satisfied
--> src\main.rs:36:25
|
36 | let vertex_buffer = glium::VertexBuffer::new(&display.borrow(), &shape).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait glium::backend::Facade
is not implemented for std::cell::Ref<'_, glium::Display>
|
= note: required by <glium::VertexBuffer<T>>::new
Thanks in advance.
main.rs:
#[macro_use]
extern crate glium;
use std::cell::{RefCell};
use std::rc::Rc;
fn main() {
use glium::{glutin};
let mut events_loop = glutin::EventsLoop::new();
let window = glutin::WindowBuilder::new();
let context = glutin::ContextBuilder::new();
// this works
// let display = glium::Display::new(window, context, &events_loop).unwrap();
// this is causing a problem
let display = Rc::new(RefCell::new(glium::Display::new(window, context, &events_loop).unwrap()));
#[derive(Copy, Clone)]
struct Vertex {
position: [f32; 2],
}
implement_vertex!(Vertex, position);
let vertex1 = Vertex { position: [-0.5, -0.5] };
let vertex2 = Vertex { position: [ 0.0, 0.5] };
let vertex3 = Vertex { position: [ 0.5, -0.25] };
let shape = vec![vertex1, vertex2, vertex3];
// this works
// let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
// this is causing a problem
let vertex_buffer = glium::VertexBuffer::new(&display.borrow(), &shape).unwrap();
}
cargo.toml:
[package]
name = "delme"
version = "0.1.0"
edition = "2018"
[dependencies]
glium = {version = "0.22.0", features = ["glutin"]}