Skip to main content

GcTraceCtx

Struct GcTraceCtx 

Source
pub struct GcTraceCtx<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> GcTraceCtx<'a>

Source

pub const fn opaque(&self) -> *mut u8

Source

pub fn add_node(&mut self, node: NonNull<GcHead>)

Submit a node to collected list regardless its color state.

Source

pub fn add<T: GcNode>(&mut self, gc_ref: GcRef<T>)

Submit a GcRef to collected list

Examples found in repository?
examples/error_handling.rs (line 216)
214    fn trace(&self, tr: &mut GcTraceCtx) {
215        if let Some(next) = self.next {
216            tr.add(next);
217        }
218    }
More examples
Hide additional examples
examples/performance_benchmark.rs (line 292)
290    fn trace(&self, tr: &mut GcTraceCtx) {
291        for neighbor in &self.neighbors {
292            tr.add(*neighbor);
293        }
294    }
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    }
examples/basic_usage.rs (line 245)
242    fn trace(&self, tr: &mut GcTraceCtx) {
243        // Trace all child nodes
244        for child in &self.children {
245            tr.add(*child);
246        }
247    }
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.