x-graphics 0.2.1

Graphics framework for X
Documentation
use crate::{error::GraphicsError, DefaultDeviceContext};

pub trait DeviceContextBackend: Clone {
    fn new() -> Result<Self, GraphicsError>
    where
        Self: Sized;
}

pub struct DeviceContext<T: DeviceContextBackend> {
    pub(crate) backend: T,
}

impl<T: DeviceContextBackend> DeviceContext<T> {
    pub fn new() -> Result<Self, GraphicsError> {
        Ok(Self {
            backend: T::new()?,
        })
    }
}

impl DeviceContext<DefaultDeviceContext> {
    pub fn default_new() -> Result<Self, GraphicsError> {
        Self::new()
    }
}