weak-self 1.0.2

WeakSelf is simple way to have a Weak pointer to yourself
Documentation
  • Coverage
  • 83.33%
    5 out of 6 items documented1 out of 5 items with examples
  • Size
  • Source code size: 17.38 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.32 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • eun-ice/weak-self
    2 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • eun-ice

WeakSelf

Build Status License Cargo Documentation

WeakSelf is simple way to have a Weak pointer inside a data structure pointing to itself.

Use Case

Sometimes you want to create a struct with a pointer to itself or just some other recursive data structure.

struct Foo {
    me: &Foo
}

impl Foo {
    pub fn new() -> Foo {
        let foo = Foo{
            me: ????
        };
        foo
    }
}

This create helps you do that:

pub struct Foo {
    weak_self: WeakSelf<Foo>
}

impl Foo {
    pub fn new() -> Arc<Foo> {
        let foo = Arc::new(Foo{
            weak_self: WeakSelf::new()
        });
        foo.weak_self.init(&foo);
        foo
    }
    
    fn weak(&self) -> Weak<Self> {
        self.weak_self.get()
    }
}

Dependencies

This package depends on std only

Usage

To use WeakSelf, add this to your Cargo.toml:

[dependencies]
weakself = "1.0.2"

License

Licensed under the terms of MIT license and the Apache License (Version 2.0).

See LICENSE-MIT and LICENSE-APACHE for details.