This crate currently supports fallible allocation on stdlib collections by adding additional functions via new traits. For example, implementing the FallibleVec trait for std::vec::Vec adds methods like try_push, which return a Result indicating the potential for allocation failure (as opposed to Vec's push which returns nothing).
This allows the crate to be introduced easily in code already using stdlib containers, but it requires the consumer to determine whether or not fallibility is desired for each call, and to be aware of all the calls which potentially allocate. To support consumers which desire consistent use of fallible allocation, this crate can also provide distinct types (e.g., TryVec as an alternative to std::vec::Vec) which provide the same function names as the stdlib containers, but add Result return values to any functions which potentially allocate and do not implement the traits which may allocate with no mechanism to return failure such as Clone. (They may implement alternative traits such as TryClone if necessary.)
Some initial work along these lines has already been done in the mp4parse-rust crate, but it has value as a more general library. Adding it to this crate should facilitate code sharing and discoverability.
This crate currently supports fallible allocation on stdlib collections by adding additional functions via new traits. For example, implementing the
FallibleVec
trait forstd::vec::Vec
adds methods liketry_push
, which return aResult
indicating the potential for allocation failure (as opposed toVec
'spush
which returns nothing).This allows the crate to be introduced easily in code already using stdlib containers, but it requires the consumer to determine whether or not fallibility is desired for each call, and to be aware of all the calls which potentially allocate. To support consumers which desire consistent use of fallible allocation, this crate can also provide distinct types (e.g.,
TryVec
as an alternative tostd::vec::Vec
) which provide the same function names as the stdlib containers, but addResult
return values to any functions which potentially allocate and do not implement the traits which may allocate with no mechanism to return failure such asClone
. (They may implement alternative traits such asTryClone
if necessary.)Some initial work along these lines has already been done in the
mp4parse-rust
crate, but it has value as a more general library. Adding it to this crate should facilitate code sharing and discoverability.