rendy_resource/
lib.rs

1//! This crate provide methods to create/destroy and otherwise manage device resources.
2//! Primarily focus on buffers and images.
3
4#![warn(
5    missing_debug_implementations,
6    missing_copy_implementations,
7    missing_docs,
8    trivial_casts,
9    trivial_numeric_casts,
10    unused_extern_crates,
11    unused_import_braces,
12    unused_qualifications
13)]
14use rendy_core as core;
15use rendy_descriptor as descriptor;
16use rendy_memory as memory;
17
18mod buffer;
19mod escape;
20mod image;
21mod set;
22
23mod resources;
24mod sampler;
25
26pub use crate::{buffer::*, escape::*, image::*, resources::*, sampler::*, set::*};
27
28/// Error creating a resource.
29#[derive(Clone, Debug, PartialEq)]
30pub enum CreationError<E> {
31    /// Failed to create an object.
32    Create(E),
33    /// Failed to allocate memory.
34    Allocate(memory::HeapsError),
35    /// Failed to bind object memory.
36    Bind(rendy_core::hal::device::BindError),
37}
38
39impl<E> std::fmt::Display for CreationError<E>
40where
41    E: std::fmt::Debug,
42{
43    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44        match self {
45            CreationError::Create(_err) => write!(fmt, "Failed to create object"), // Uncomment after gfx-0.4.1 std::fmt::Display::fmt(err, fmt),
46            CreationError::Allocate(err) => write!(fmt, "Failed to create object: {}", err),
47            CreationError::Bind(err) => write!(fmt, "Failed to create object: {:?}", err),
48        }
49    }
50}
51
52impl<E> std::error::Error for CreationError<E>
53where
54    E: std::error::Error + 'static,
55{
56    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
57        match self {
58            CreationError::Create(err) => Some(err),
59            CreationError::Allocate(err) => Some(err),
60            CreationError::Bind(err) => Some(err),
61        }
62    }
63}