Skip to content

error structs prototype #622

Description

@alejandro-vaz

prototype having the errors as separate structs that are instantiated instead of an enum

current model:

#[derive(Debug)]
pub enum CollectionAllocErr {
    /// Overflow `usize::MAX` or other error during size computation
    CapacityOverflow,
    /// The allocator return an error
    AllocErr {
        /// The layout that was passed to the allocator
        layout: Layout
    }
}

the current model is a simple enum with two variants, which means that neither variant can exist independently but as an instance of the enum

then, the infallible function is used to either panic on an error result or call handle_alloc_error

the proposal is for something like

pub struct CapacityOverflow;

pub struct AllocationError(Layout);

// if necessary an enum encompassing both

pub trait Handle { // handle the error, implemented for both errors
    // one function that either panics or handles alloc error
    // depending on the implementation for that type
}

which will allow us to have precise error signatures and avoid the infallible helper

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

experimentPossible experimentsr-refactorrelated to refactoring

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions