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

no-std try-insert-ext

Extends various types with try_insert_with methods

1 unstable release

0.1.0 Feb 22, 2021

#30 in #extend

Download history 5/week @ 2024-02-19 14/week @ 2024-02-26 136/week @ 2024-03-04 7/week @ 2024-03-11 39/week @ 2024-03-18

197 downloads per month

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