So if I understand it correctly the way to empty a adw::Bin is to set it’s child to None. However None doesn’t implement IsA<gtk::Widget>. So is there a way to do this properly?
let bin = adw::Bin::new();
bin.set_child(None); // <- cannot satisfy `_: IsA<gtk4::Widget>`
You need a “typed” None; you can either or None::<>k::Widget> or gtk::Widget::NONE. The wrapper classes provided by the Rust bindings provide a NONE constant value for this particular case.
To give some background why something like None is actually typed, consider the following code
fn unwrap_or_default<T: Default>(v: Option<T>) -> T {
match v {
Some(v) => v,
None => T::default(),
}
}
let x: Option<u32> = None;
let y: Option<String> = None;
println!("{}", unwrap_or_default(x)); // Calls into u32's Default impl
println!("{}", unwrap_or_default(y)); // Calls into String's Default impl
println!("{}", unwrap_or_default(None)); // Impossible to know which Default impl should be used here