Skip to content

[FEATURE REQUEST] FromValue::from_value should return a Result #1047

@ranfdev

Description

@ranfdev

I want to add support for TryFrom in the ValueDelegate macro

Eg, I want to do this:

#[derive(ValueDelegate)]
#[value_delegate(try_from = u32)]
struct MyU16(u16);

Clearly, the conversion from a u32 to a u16 could fail.
FromValue::from_value should return an error, else I can't return the error from the call of TryFrom::try_from.

Currently FromValue has an associated Checker which checks the type in the glib type system and throws an error when the conversion is not possible. A Checker can't be made to handle TryFrom though, because that would require calling try_from inside FromValue::check and FromValue::from_value, which is a waste of resources.

Or maybe I just panic if TryFrom fails

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions