I am aware of cell.rs - source .
I have:
x: Ref<Option<T>>
I want:
y: Option<Ref<T>>
Is there a way to do this?
EDIT: Here, Ref refers to Ref in std::cell - Rust
I am aware of cell.rs - source .
I have:
x: Ref<Option<T>>
I want:
y: Option<Ref<T>>
Is there a way to do this?
EDIT: Here, Ref refers to Ref in std::cell - Rust
Something like this should work:
use std::cell::{Ref,RefCell};
fn transpose_ref_opt<T>(x:Ref<'_,Option<T>>)->Option<Ref<'_,T>> {
if x.is_none() { None }
else { Some(Ref::map(x, |x| x.as_ref().unwrap()))}
}
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.