#default-value #default #traits #empty #uninitialized #macro-derive #no-alloc

no-std partial-default

Provides PartialDefault, a trait similar to Default but with fewer guarantees

1 unstable release

0.1.0 Oct 25, 2023

#1351 in Rust patterns

Download history 1731/week @ 2024-06-23 976/week @ 2024-06-30 1844/week @ 2024-07-07 1405/week @ 2024-07-14 1291/week @ 2024-07-21 1356/week @ 2024-07-28 1562/week @ 2024-08-04 1418/week @ 2024-08-11 1842/week @ 2024-08-18 1732/week @ 2024-08-25 1331/week @ 2024-09-01 1407/week @ 2024-09-08 1251/week @ 2024-09-15 1561/week @ 2024-09-22 1923/week @ 2024-09-29 1344/week @ 2024-10-06

6,196 downloads per month

AGPL-3.0-only

16KB

PartialDefault is a trait for giving a type a non-useful default value.

The standard Default trait documents its purpose as providing a "useful" default value. However, some types (such as a Credential) don't have meaningful defaults, and yet there are still uses for a known-initialized value:

PartialDefault satisfies this niche. A type that implements PartialDefault can provide a value that is safe to drop or assign over, but promises nothing else about that value. It provides a derive macro (opt-in, with the derive feature) and is no_std compatible.

License and Contributions

PartialDefault was made to support libsignal, but is available for general use under the AGPLv3. Still, this is meant to be a low-maintenance crate; do not expect active support or progress on feature requests.

Signal does accept external contributions to this project; however, signing a CLA (Contributor License Agreement) is required for all contributions.

Copyright 2023 Signal Messenger, LLC.

The partial-default-derive crate contains code adapted from the rust-smart-default crate, Copyright (c) 2017 Idan Arye, under the MIT license.

Dependencies

~105KB