Drop ownership from "method position"

Related tags

Utilities disown
Overview

disown

Drop ownership from "method position".

Motivation

Normally, unowned data is automatically dropped at the end of its residing block. We can also ignore unuseful return values with ;, which is essentially a T -> () transformation. However, there are cases where we wish to drop ownership and return cleanly with a (), but don't want to involve ; (such as in closures or simple match arms). We could use [std::mem::drop] for this, but drop is a function, not a method, and would visually mar a nice chain of method calls.

Hence the [Disown] trait and its method disown. It is drop, but in "method position".

use disown::Disown;
use std::collections::HashSet;

enum Person {
    Bob,
    Sam,
}

let mut set = HashSet::new();
let person = Person::Bob;

match person {
  Person::Bob => set.insert(0).disown(),
  Person::Sam => set.insert(1).disown(),
}

HashSet::insert returns a bool, not (), and the above code would not compile without opening a pair of {} and using a ;, which doesn't look as nice.

License: MIT

You might also like...
πŸ±β€πŸ‘€ Drop-in HTTP replacement module for Garry's Mod

πŸ±β€πŸ‘€ gmsv_reqwest This module is a drop-in replacement for Garry's Mod's HTTP function, inspired by gmsv_chttp created by timschumi. The module uses

A drop-in replacement for `dapp` and `seth` in Rust

dapptools.rs Rust port of DappTools dapp example Usage Run Solidity tests Any contract that contains a function starting with test is being tested. Th

Drop-in proxy for Discord gateway connections and sessions allowing for zero downtime deploys

gateway-proxy This is a very hacky project, so it might stop working if Discord changes their API core. This is unlikely, but keep that in mind while

A (mostly) drop-in replacement for Rust's Result that provides backtrace support

Errant A (mostly) drop-in replacement for Rust's Result that provides backtrace support. Please note that Errant is still very early in development an

Contains the source code to compile the drop'in language into WebAssembly files

drop'in compiler This repository contains the source code to compile the drop'in language into WebAssembly files. This source code is in an experiment

drop-in replacement for libfuzzer
drop-in replacement for libfuzzer

Fazi A reimplementation of libfuzzer in Rust with some improvements Supported Features libFuzzer's mutations SanCov feedback Building without a main()

 DexiosGUI - Simple cross-platform drag-and-drop Dexios file encryption
DexiosGUI - Simple cross-platform drag-and-drop Dexios file encryption

DexiosGUI Simple cross-platform drag-and-drop Dexios file encryption. Latest Windows x64 release is here. DexiosGUI is a Qt/C++ app for encrypt and de

messloc is a drop in replacement for malloc that can transparently recover from memory fragmentation without any changes to application code.
messloc is a drop in replacement for malloc that can transparently recover from memory fragmentation without any changes to application code.

messloc is a drop in replacement for malloc that can transparently recover from memory fragmentation without any changes to application code. Goals Al

A simple tool to test sqlx with postgres. It will automatically create a database and drop it after the test.

sqlx-db-tester This a tool to test sqlx with postgres. It only supports tokio runtime at this moment. How to use it You should first create a TestDb d

Make a DAO Drop!

DAO drop tool This tool parses a Cosmos SDK chain export JSON file, to produce a CSV list of addresses and amounts. It can handle extremely large file

Modern Drop-in Replacement for Nginx AutoIndex / FancyIndex!
Modern Drop-in Replacement for Nginx AutoIndex / FancyIndex!

MeowIndex A cute, feature-rich file listing module to replace nginx's autoindex / fancyindex. Features List files Show file icons Clickable, length-sa

Fast, concurrent, arena-based allocator with drop support

blink-alloc Blink-alloc is extremely fast allocator based on the common idea of allocating linearly zipping a cursor through memory chunk and reset ev

Drop-in embedded database
Drop-in embedded database

Struct DB πŸ”§ πŸ”© Provides a drop-in, fast, and embedded database solution, focusing on maintaining coherence between Rust types and stored data with mi

A tiling layout engine for egui with drag-and-drop and resizing
A tiling layout engine for egui with drag-and-drop and resizing

egui_tiles Layouting and docking for egui. Supports: Horizontal and vertical layouts Grid layouts Tabs Drag-and-drop docking Trying it cargo r --examp

A mostly drop-in replacement for mercantile written w/ rust, plus several other util(e)ities.

utiles utiles = utils + tiles A mostly drop-in replacement for mercantile written w/ rust, plus several other util(e)ities. Installation pip install u

A lightweight, no-fuss, drop-in replacement for Rudderstack

Welcome to Stilgar! Stilgar is a lightweight, no-fuss, drop-in replacement for Rudderstack. Key features: Seamlessly compatible with all Rudderstack c

Drop-in replacement for the Actix Web HTTP Logger middleware

actix-contrib-logger Logger middleware for the Actix Web framework. Actually it's a copy & paste from the official Logger middleware (original source

A drop-in replacement for std::time::Instant that is faster and more accurate.

Fastant A drop-in replacement for std::time::Instant that measures time with high performance and high accuracy powered by Time Stamp Counter (TSC). U

Owner
Colin Woodbury
I write Rust, Haskell, and Go. ηΎεœ¨γ‚«γƒŠγƒ€γ§ι–‹η™Ίγ€‚
Colin Woodbury
messloc is a drop in replacement for malloc that can transparently recover from memory fragmentation without any changes to application code.

messloc is a drop in replacement for malloc that can transparently recover from memory fragmentation without any changes to application code. Goals Al

null 11 Dec 10, 2022
Drop-in embedded database

Struct DB ?? ?? Provides a drop-in, fast, and embedded database solution, focusing on maintaining coherence between Rust types and stored data with mi

Vincent Herlemont 7 May 19, 2023
A mostly drop-in replacement for mercantile written w/ rust, plus several other util(e)ities.

utiles utiles = utils + tiles A mostly drop-in replacement for mercantile written w/ rust, plus several other util(e)ities. Installation pip install u

jesse 5 Jun 20, 2023
Drop-in Access Control via NFT Ownership

niftygate - Signature-Based Authenticating Proxy What is it? niftygate is a proxy for HTTP services, that validates signatures, providing an AuthN lay

Chris Olstrom 70 Jan 3, 2023
A low-level I/O ownership and borrowing library

This library introduces OwnedFd, BorrowedFd, and supporting types and traits, and corresponding features for Windows, which implement safe owning and

Dan Gohman 74 Jan 2, 2023
P2P Network to verify authorship & ownership, store & deliver proofs.

Anagolay Network Node Anagolay is a next-generation framework for ownerships, copyrights and digital licenses. ?? Local Development The installation a

Anagolay Network 5 May 30, 2022
Like a cell, but make lifetimes dynamic instead of ownership

LendingCell is a mutable container that allows you to get an owned reference to the same object. When the owned reference is dropped, ownership return

Kalle Samuels 19 Dec 15, 2022
An ownership model that is used to replace the Ring in Linux.

std-ownership An ownership model that is used to replace the Ring in Linux. It's 10x faster than Ring in Syscall. Overview The ownership system allows

Rhodes 4 Feb 13, 2023
Rustyread is a drop in replacement of badread simulate.

Rustyread is a drop in replacement of badread simulate. Rustyread is very heavily inspired by badread, it reuses the same error and quality model file. But Rustyreads is multi-threaded and benefits from other optimizations.

Pierre Marijon 20 Oct 1, 2022
age-encrypted secrets for NixOS; drop-in replacement for agenix

ragenix ragenix provides age-encrypted secrets for NixOS systems which live in the Nix store and are decrypted on system activation. Using ragenix to

YAXI 91 Jan 8, 2023