#methods #error #entry #type #extend #options #map

no-std try-insert-ext

Extends various types with try_insert_with methods

1 unstable release

0.1.0 Feb 22, 2021

#35 in #extend

MIT license

13KB
225 lines

try-insert-ext

This library provides extension traits for std types, adding or_try_insert_with (or equivalent) methods for Option, map Entry types, and HashSet. These act similarly to or_insert_with methods, but taking a function that returns a Result, and inserting only if the function returns Ok, otherwise returning the Err.


lib.rs:

Provides extension traits for Option and map Entry types, adding try_insert methods. These methods take possibly empty containers, and if empty, run an initialization function. If this function errors, an error is returned. Otherwise, the initialized value is returned.

No runtime deps

Features