4 ms·
Maybe I’m misunderstanding, but why is that not possible with a Fn(_: T) -> T
by stouset 1y ago
Maybe I’m misunderstanding, but why is that not possible with a
Fn(_: T) -> T
- iknowstuff 1y agoIt totally is https://docs.rs/tokio-uring/latest/tokio_uring/fs/struct.File.html#method.read_at https://docs.rs/tokio-uring/latest/tokio_uring/fs/struct.Fil...
- dwattttt 1y agoAs sibling notes, it is. It's very rarely seen though. One place you might see something like it is if an API takes ownership, but returns it on error; you see the error side carry the resource you gave it, so you could try again.
- IshKebab 1y agoHow is that different to Fn(_: &mut T) ?
- Soft 1y agoIn the former the caller does not retain access to T until Fn returns.
- andyferris 1y agoI think I'm lost. If I give a mutable reference to a function... I can't access it (even read it) until it returns, no? What is different?
- zbentley 1y agoLet's say a function "foo" calls "fn bar(_: &mut T) -> ()". When passing a mutable reference, the lifetime of the object is largely decided by "foo" (with some caveats). Now, let's say that "foo" instead calls "fn bar(_: T) -> T". When passing the object itself, the lifetime is largely decided/decide-able by "bar".
- IshKebab 1y agoThat's true of mutable references too though isn't it? In fact lots of people have suggested they should really have been called "exclusive references", since you can actually mutate some objects through non-exclusive references (called "interior mutability" normally).