pnevyk / gryf

Graph data structure library aspiring to be convenient, versatile, correct and performant.
MIT License
69 stars 1 forks source link

Fallible methods #34

Closed pnevyk closed 1 year ago

pnevyk commented 1 year ago

Some operations on graph can fail. A nice example is add_edge(src, dst, data), where

For fallible operation, we may introduce fallible API such as try_add_edge that would return a Result. For trait implementations, only the fallible method would be required and the panicking variant would have a default implementation that calls try_ counterpart and unwraps the result.

Each fallible method should have a corresponding Error type that should be general enough to cover all practical cases. Making the error types as associative types would be an overkill and complicate the API.

pnevyk commented 1 year ago

It is not a priority for the foreseeable future, but all methods that add something (add vertex, add edge) can have CapacityOverflow error variant, which would be used by storages constrained on their capacity (e.g., fixed-size, stack-allocated graphs for embedded devices). Name of the error is taken from std::collections::TryReserveErrorKind.