Change coral::path::joined to return coral::expected

This commit is contained in:
kayomn 2023-03-01 00:30:37 +00:00
parent 261b62fc2d
commit c53fd30cc2

View File

@ -7,6 +7,15 @@ export namespace coral {
* Platform-generalized identifier for a resource in a [fs].
*/
struct path {
/**
* Errors that may occur during a path joining operation.
*
* [join_error::overflow] signals that the given path join exceeds the maximum valid length of a path.
*/
enum class join_error {
overflow,
};
/**
* Maximum path length.
*/
@ -83,14 +92,11 @@ export namespace coral {
}
/**
* Returns a new [path] composed of the current path joined with `text`.
*
* *Note:* should the new path exceed [max] bytes in size, an empty [path] is returned instead.
*
* *Note:* should the new path exceed [max] bytes in size, an empty [path] is returned instead.
* Attempts to create a new path composed from the current path joined with `text`, returning it or a
* [join_error] if it failed.
*/
constexpr path joined(slice<char const> const & text) const {
if (text.length > this->buffer[max]) return path{};
constexpr expected<path, join_error> joined(slice<char const> const & text) const {
if (text.length > this->buffer[max]) return join_error::overflow;
path joined_path = *this;