How to fill generic type nowhere to be caught?

I'm working on some abstraction using generic types.

But the problem is, type T is embedded in an Option, so when I insert a None it cannot be autoly derived. While at the same time T is an Fn, making it impossible for me to write it myself, without probably existing unstable tricks of typeof.

So how shall I implement such a function:

fn portal(src: Rc<RefCell<dyn Referent>>, dest: Rc<RefCell<dyn Referent>>) -> Passage<T> {
    Passage::<T> {
        link_src: src,
        link_dest: dest,
        gen_dest: None,
    }
}

And please tell me if I'm misusing anything.

Since the type doesn't matter, you can use anything that implements the required trait; concretely, the function pointer type fn() -> Rc<RefCell<dyn Referent>>.


I don't exactly understand why you think that is the case. If you are thinking that only closures (which are unnameable) implement the Fn traits, then you are mistaken. The above example clearly demonstrates that other types implement those traits, too (fn pointers and fn items, as well as the trait object type dyn Fn – the latter of which should hopefully be obvious).

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.