Skip to content
/ cease Public

A simplistic monadic error handling library for C

License

Notifications You must be signed in to change notification settings

maxicot/cease

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cease

cease is a simplistic C23 library for monadic error handling. Refer to include/cease.h for documentation.

Installation

Can be installed with CMake using FetchContent.

First, specify its installation in CMakeLists.txt:

include(FetchContent)

FetchContent_Declare(
    cease
    GIT_REPOSITORY https://github.com/maxicot/cease.git
    GIT_TAG main
)

FetchContent_MakeAvailable(cease)

Then it can be treated as a normal library in your CMakeLists. After you've linked it, you merely need to include it in your C code:

#include "cease.h"

Usage

A simple usage example:

#include "cease.h"

// The return type is `int`
ResultMonad divide(int a, int b) {
    if (b == 0) {
        return result_error(EDOM);
    }

    int result = a / b;
    return result_from_unallocated(&result, sizeof(result));
}

int main() {
    result_unwrap(divide(1, 0)); // panics
}

Disadvantages

  1. Type-unsafety;
  2. Allocation overhead.

Not the most idiomatic way to handle errors in C, the language also not being particularly suitable for its implementation (at least one that would be any good). Advised against in production.

About

A simplistic monadic error handling library for C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published