A Self-Reference Helper For Rust.

Overview

Self-Reference

A Self-Refernece Helper (Inspired From Selfie)

this crate provides safe access to its self-reference. the main idea is not initializing references when object not pinned(which is not safe and makes many self-referenial crate more complex) providing only pinned reference makes lot more easier to design self-referential object. on self-reference crate. you only can initialize reference object that has 'static lifetime means always safe.

Initializing Reference Object

The major difference from other self-referential crate is initializing referential object. you only can initialize reference object that has 'static lifetime

let mut reference: SelfReference<String, Ref<str>> = SelfReference::new(String::new(), || {
    // you can't get reference of object while initialization.
    // only possible cases are reference that has `'static` lifetime.
    ""
});
pin_mut!(reference);

// this is totally SAFE. this lowers `'static` lifetime into some other lifetime.
reference.get_ref();

Reset Mechanism

The only way to initialize reference object is using reset method. remember!! you can use reset method when SelfReference object is pinned.

let mut reference: SelfReference<String, Ref<str>> = SelfReference::new("self-reference".to_string(), || "");
pin_mut!(reference);

// You can reset object to set referencial object to hold object itself.
reference.reset_unpin(|s| &s[..4]);
println!("{}", reference.get_ref()); // prints "self"
You might also like...
Experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code

Diplomat is an experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code. With Diplomat, you can simply define Rust APIs to be exposed over FFI and get high-level C, C++, and JavaScript bindings automatically!

Aws-sdk-rust - AWS SDK for the Rust Programming Language

The AWS SDK for Rust This repo contains the new AWS SDK for Rust (the SDK) and its public roadmap. Please Note: The SDK is currently released as a dev

Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps.

rust-yew-axum-tauri-desktop template Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps. Crates frontend: Yew frontend app for de

A lightning fast version of tmux-fingers written in Rust, copy/pasting tmux like vimium/vimperator
A lightning fast version of tmux-fingers written in Rust, copy/pasting tmux like vimium/vimperator

tmux-thumbs A lightning fast version of tmux-fingers written in Rust for copy pasting with vimium/vimperator like hints. Usage Press ( prefix + Space

A command-line tool collection to assist development written in RUST

dtool dtool is a command-line tool collection to assist development Table of Contents Description Usage Tips Installation Description Now dtool suppor

Rust mid-level IR Abstract Interpreter

MIRAI MIRAI is an abstract interpreter for the Rust compiler's mid-level intermediate representation (MIR). It is intended to become a widely used sta

Migrate C code to Rust
Migrate C code to Rust

C2Rust helps you migrate C99-compliant code to Rust. The translator (or transpiler) produces unsafe Rust code that closely mirrors the input C code. T

C to Rust translator

Corrode: Automatic semantics-preserving translation from C to Rust This program reads a C source file and prints an equivalent module in Rust syntax.

Astronomical algorithms in Rust

astro-rust Contents API Docs About Usage Contributing References About astro-rust is a library of advanced astronomical algorithms for the Rust progra

Owner
Jun Ryung Ju
Jun Ryung Ju
Simple and fast git helper functions

Simple and fast git helper functions

LongYinan 126 Dec 11, 2022
Helper macros: autoimpl, impl_scope

Impl-tools A set of helper macros Macros Autoimpl #[autoimpl] is a variant of #[derive], supporting: explicit generic parameter bounds ignored fields

null 38 Jan 1, 2023
Flexible snowflake generator, reference snoyflake and leaf.

Flexible snowflake generator, reference snoyflake and leaf.

Egccri 2 May 6, 2022
A self-contained, single-binary Rust and Leptos application for remote Wake-on-LAN

Remote Wake-on-LAN with Rust and Leptos A self-contained, single-binary Rust and Leptos application serving a web interface to wake another device on

Valentin Bersier 6 Jan 28, 2023
Octopus Linguistics for self-hosted runners

octoling Octopus Linguistics for self-hosted runners. Early PoC Allows to create self-hosted ephemeral runners on various providers. (currently only s

Mary 5 Nov 1, 2021
Self-Hosted alternative to GitHub Gists

Gists Self-Hosted GitHub Gists Features Upload code snippets Syntax Highlighting Comments Versioning through Git Fork gists Gist privacy: public, unli

Aravinth Manivannan 52 Dec 22, 2022
Manage self-hosted Supabase instances with an easy to use API & Web Portal (soon)

SupaManager A project by Harry Bairstow; Manage self-hosted Supabase instances with an easy to use API & Web Portal (soon) ⚠️ Note: The project is in

Harry Bairstow 11 Sep 15, 2022
A stupidly simple and easy to self-host, personal server for file hosting on the web

Grasswave CDN A stupidly simple and easy to self-host, personal server for file hosting on the web. Written in Rust. Thanks, @Maciejowski, for the sty

Rafał Baran 3 Jan 3, 2023
Twidge is a fresh approach to productivity. It integrates with your workflow and allows you to be your most productive self.

Twidge A productivity app which is an extension to your mind Twidge is a cross platform productivity app, powered by rust, tauri, prisma-client-rust T

Twidge 187 Jun 28, 2023
k-mer counter in Rust using the rust-bio and rayon crates

krust is a k-mer counter written in Rust and run from the command line that will output canonical k-mers and their frequency across the records in a f

null 14 Jan 7, 2023