pub struct GcTraceCtx<'a> { /* private fields */ }Implementations§
Source§impl<'a> GcTraceCtx<'a>
impl<'a> GcTraceCtx<'a>
pub const fn opaque(&self) -> *mut u8
Sourcepub fn add_node(&mut self, node: NonNull<GcHead>)
pub fn add_node(&mut self, node: NonNull<GcHead>)
Submit a node to collected list regardless its color state.
Sourcepub fn add<T: GcNode>(&mut self, gc_ref: GcRef<T>)
pub fn add<T: GcNode>(&mut self, gc_ref: GcRef<T>)
Submit a GcRef to collected list
Examples found in repository?
More examples
examples/advanced_features.rs (line 356)
354 fn trace(&self, tr: &mut GcTraceCtx) {
355 if let Some(partner) = self.partner {
356 tr.add(partner);
357 }
358 }
359}
360
361impl std::fmt::Display for CyclicNode {
362 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
363 write!(f, "CyclicNode({})", self.name)
364 }
365}
366
367/// Tree node
368#[derive(Debug)]
369struct TreeNode {
370 name: String,
371 children: Vec<GcRef<TreeNode>>,
372}
373
374impl TreeNode {
375 fn new(name: &str) -> Self {
376 Self {
377 name: name.to_string(),
378 children: Vec::new(),
379 }
380 }
381
382 fn add_child(&mut self, child: GcRef<TreeNode>) {
383 self.children.push(child);
384 }
385}
386
387impl GcTrace for TreeNode {
388 fn trace(&self, tr: &mut GcTraceCtx) {
389 for child in &self.children {
390 tr.add(*child);
391 }
392 }
393}
394
395impl std::fmt::Display for TreeNode {
396 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
397 write!(
398 f,
399 "TreeNode({}, {} children)",
400 self.name,
401 self.children.len()
402 )
403 }
404}
405
406/// Data container
407#[derive(Debug)]
408struct DataContainer {
409 root: GcRef<TreeNode>,
410 metadata: Vec<i32>,
411 optional_data: Option<GcRef<TreeNode>>,
412}
413
414impl GcTrace for DataContainer {
415 fn trace(&self, tr: &mut GcTraceCtx) {
416 tr.add(self.root);
417 if let Some(data) = self.optional_data {
418 tr.add(data);
419 }
420 }pub fn take_nodes(&mut self) -> Vec<NonNull<GcHead>>
Auto Trait Implementations§
impl<'a> Freeze for GcTraceCtx<'a>
impl<'a> RefUnwindSafe for GcTraceCtx<'a>
impl<'a> !Send for GcTraceCtx<'a>
impl<'a> !Sync for GcTraceCtx<'a>
impl<'a> Unpin for GcTraceCtx<'a>
impl<'a> UnsafeUnpin for GcTraceCtx<'a>
impl<'a> UnwindSafe for GcTraceCtx<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more