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 374)
372 fn trace(&self, tr: &mut GcTraceCtx) {
373 if let Some(partner) = self.partner {
374 tr.add(partner);
375 }
376 }
377}
378
379impl std::fmt::Display for CyclicNode {
380 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
381 write!(f, "CyclicNode({})", self.name)
382 }
383}
384
385/// Tree node
386#[derive(Debug)]
387struct TreeNode {
388 name: String,
389 children: Vec<GcRef<TreeNode>>,
390}
391
392impl TreeNode {
393 fn new(name: &str) -> Self {
394 Self {
395 name: name.to_string(),
396 children: Vec::new(),
397 }
398 }
399
400 fn add_child(&mut self, child: GcRef<TreeNode>) {
401 self.children.push(child);
402 }
403}
404
405impl GcTrace for TreeNode {
406 fn trace(&self, tr: &mut GcTraceCtx) {
407 for child in &self.children {
408 tr.add(*child);
409 }
410 }
411}
412
413impl std::fmt::Display for TreeNode {
414 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
415 write!(
416 f,
417 "TreeNode({}, {} children)",
418 self.name,
419 self.children.len()
420 )
421 }
422}
423
424/// Data container
425#[derive(Debug)]
426struct DataContainer {
427 root: GcRef<TreeNode>,
428 metadata: Vec<i32>,
429 optional_data: Option<GcRef<TreeNode>>,
430}
431
432impl GcTrace for DataContainer {
433 fn trace(&self, tr: &mut GcTraceCtx) {
434 tr.add(self.root);
435 if let Some(data) = self.optional_data {
436 tr.add(data);
437 }
438 }pub fn take_nodes(&mut self) -> Vec<NonNull<GcHead>>
Auto Trait Implementations§
impl<'a> !Send for GcTraceCtx<'a>
impl<'a> !Sync for GcTraceCtx<'a>
impl<'a> Freeze for GcTraceCtx<'a>
impl<'a> RefUnwindSafe 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