Skip to content

Option<T> does not implement OwnedToVariant when T implements only OwnedToVariant. #869

Open
@B-head

Description

@B-head

For example, the following code will not work.

#[derive(NativeClass)]
#[no_constructor]
struct Foo {}

#[methods]
impl Foo {
    #[export]
    fn get(&self, _owner: &Reference) -> Option<Instance<Foo, Unique>> {
            Some((Foo{}).emplace())
    }
}

This issue can be avoided by using into_shared() to perform type conversion.

#[derive(NativeClass)]
#[no_constructor]
struct Foo {}

#[methods]
impl Foo {
    #[export]
    fn get(&self, _owner: &Reference) -> Option<Instance<Foo>> {
            Some((Foo{}).emplace().into_shared())
    }
}

I tried to solve this issue, but implementing impl<T: OwnedToVariant > OwnedToVariant for Option<T> causes a conflict with impl<T: ToVariant> OwnedToVariant for T.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking-changeIssues and PRs that are breaking to fix/merge.c: coreComponent: core (mod core_types, object, log, init, ...)quality-of-lifeNo new functionality, but improves ergonomics/internalsstatus: upstreamIssue that originates in an upstream project and can't be dealt with here.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions