<html><head></head><body><div>On Thu, 2021-04-08 at 21:54 -0500, kakakong wrote:</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div>fn sink_event(&self, element: &Self::Type, event: gst::Event) -> bool {<br></div><div>    match event.view() {<br></div><div>        let state = self.state.lock().unwrap();<br></div><div>        EventView::StreamStart(_) => {<br></div><div>            state.inspect_timer<br></div><div>                .schedule_repeating(chrono::Duration::seconds(1), move ||<br></div><div>unsafe {<br></div><div>                    // how to get self and element instance<br></div><div>                })<br></div><div>                .ignore();<br></div><div>        }<br></div><div>        _ => (),<br></div><div>    }<br></div><div>}<br></div><div><br></div><div>i need get element state and element instance's real-time data.<br></div><div>i attempt to use raw pointer, but it not work;</div></blockquote><div><br></div><div>In the code above you have `element` which is the element instance, and `self` which should be the private/implementation state of it.</div><div><br></div><div>If you want to pass that to the closure, you could do something like</div><div><br></div><div><font face="monospace">    let element_clone = element.clone();</font></div><div><font face="monospace">    state.inspect_timer.schedule_repeating(chrono::Duration::seconds(1), move || {</font></div><div><font face="monospace">        let imp = YourElementType::from_instance(&element_clone); // This is the same as `self` outside the closure</font></div><div><font face="monospace">        [...]</font></div><div><font face="monospace">    })</font></div><div><font face="monospace">    .ignore();</font></div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote><div><br></div><div>Note that this keeps the element alive until the closure is dropped.</div><div><br></div><div>See <a href="https://gtk-rs.org/gtk-rs/glib/subclass/types/trait.ObjectSubclassExt.html#tymethod.from_instance">https://gtk-rs.org/gtk-rs/glib/subclass/types/trait.ObjectSubclassExt.html#tymethod.from_instance</a> for details.</div><div><br></div><div>There are also various examples of this pattern in <a href="https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs">https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs</a></div><div><br></div><div><span><pre>-- <br></pre><div data-evo-paragraph="" class="" style="width: 71ch;" data-evo-signature-plain-text-mode="">Sebastian Dröge, Centricular Ltd · <a href="http://www.centricular.com">https://www.centricular.com</a></div><div data-evo-paragraph="" class="" style="width: 71ch;"><br></div></span></div></body></html>