1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! This crate provide methods to create/destroy and otherwise manage device resources.
//! Primarily focus on buffers and images.

#![warn(
    missing_debug_implementations,
    missing_copy_implementations,
    missing_docs,
    trivial_casts,
    trivial_numeric_casts,
    unused_extern_crates,
    unused_import_braces,
    unused_qualifications
)]
use rendy_core as core;
use rendy_descriptor as descriptor;
use rendy_memory as memory;

mod buffer;
mod escape;
mod image;
mod set;

mod resources;
mod sampler;

pub use crate::{buffer::*, escape::*, image::*, resources::*, sampler::*, set::*};

/// Error creating a resource.
#[derive(Clone, Debug, PartialEq)]
pub enum CreationError<E> {
    /// Failed to create an object.
    Create(E),
    /// Failed to allocate memory.
    Allocate(memory::HeapsError),
    /// Failed to bind object memory.
    Bind(rendy_core::hal::device::BindError),
}

impl<E> std::fmt::Display for CreationError<E>
where
    E: std::fmt::Debug,
{
    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            CreationError::Create(_err) => write!(fmt, "Failed to create object"), // Uncomment after gfx-0.4.1 std::fmt::Display::fmt(err, fmt),
            CreationError::Allocate(err) => write!(fmt, "Failed to create object: {}", err),
            CreationError::Bind(err) => write!(fmt, "Failed to create object: {:?}", err),
        }
    }
}

impl<E> std::error::Error for CreationError<E>
where
    E: std::error::Error + 'static,
{
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            CreationError::Create(err) => Some(err),
            CreationError::Allocate(err) => Some(err),
            CreationError::Bind(err) => Some(err),
        }
    }
}