I/O module

Cnx's I/O API extends its formatting API to I/O

Standard I/O in Cnx has the same requirements, functionality, and syntax as string formatting via
cnx_format(format_string, ...) and the CnxFormat Trait. Currently only formatted output is feature complete, but formatted input is planned.

Usage examples:

// use it to perform basic logging:
#define LOG(format_string, ...) println((format_string) __VA_OPT__(,) __VA_ARGS__)
#define LOG_WITH_ALLOCATOR(format_string, allocator, ...) \
                println_with_allocator((format_string), allocator, __VA_OPT__(,) __VA_ARGS__)

void func(void) {
    let f = 0;
    let y = 24;
    let j = 42;
    // do things with them...
    LOG("f: {}, y: {}, j: {}", f, y, j);
    // continue doing things...
}
// use it directly:
void func2(void) {
    let_mut vec = cnx_vector_new(u32);
    ranged_for(i, 0, 10) {
        cnx_vector_push_back(vec, i);
    }
    println("vec: {}", as_format_t(CnxVector(u32), vec));
}

Defines

#define fprint_with_allocator(file_ptr, format_string, allocator, ...)
Formats the given arguments into the specified format string then prints it to the given file.
#define fprint(file_ptr, format_string, ...)
Formats the given arguments into the specified format string then prints it to the given file.
#define print_with_allocator(format_string, allocator, ...)
Formats the given arguments into the specified format string then prints it to stdout
#define print(format_string, ...)
Formats the given arguments into the specified format string then prints it to stdout
#define eprint_with_allocator(format_string, allocator, ...)
Formats the given arguments into the specified format string then prints it to stderr
#define eprint(format_string, ...)
Formats the given arguments into the specified format string then prints it to stderr
#define fprintln(file_ptr, format_string, ...)
Formats the given arguments into the specified format string then prints it to the given file, followed by a newline.
#define println_with_allocator(format_string, allocator, ...)
Formats the given arguments into the specified format string then prints it to stdout, followed by a newline.
#define println(format_string, ...)
Formats the given arguments into the specified format string then prints it to stdout, followed by a newline.
#define eprintln_with_allocator(format_string, allocator, ...)
Formats the given arguments into the specified format string then prints it to stderr, followed by a newline.
#define eprintln(format_string, ...)
Formats the given arguments into the specified format string then prints it to stderr, followed by a newline.

Define documentation

#define fprint_with_allocator(file_ptr, format_string, allocator, ...)

Formats the given arguments into the specified format string then prints it to the given file.

Parameters
file_ptr - The file to print the formatted string to
format_string - The format string specifying how text and arguments should be formatted
allocator - The allocator to allocate the formatted string with
... - The parameter pack of arguments to format

Formats the arguments according to the given format string, allocating the output string and any intermediaries with the given allocator. Requires that the number of specifiers in the format string matches the number of arguments in the parameter pack and that all arguments in the parameter pack have an accessible automatic conversion to CnxFormat via CNX_AS_FORMAT_USER_SUPPLIED_TYPES or have been explicitly converted to CnxFormat already.

#define fprint(file_ptr, format_string, ...)

Formats the given arguments into the specified format string then prints it to the given file.

Parameters
file_ptr - The file to print the formatted string to
format_string - The format string specifying how text and arguments should be formatted
... - The parameter pack of arguments to format

Formats the arguments according to the given format string, allocating the output string and any intermediaries with the default system allocator. Requires that the number of specifiers in the format string matches the number of arguments in the parameter pack and that all arguments in the parameter pack have an accessible automatic conversion to CnxFormat via CNX_AS_FORMAT_USER_SUPPLIED_TYPES or have been explicitly converted to CnxFormat already.

#define print_with_allocator(format_string, allocator, ...)

Formats the given arguments into the specified format string then prints it to stdout

Parameters
format_string - The format string specifying how text and arguments should be formatted
allocator - The allocator to allocate the formatted string with
... - The parameter pack of arguments to format

Formats the arguments according to the given format string, allocating the output string and any intermediaries with the given allocator. Requires that the number of specifiers in the format string matches the number of arguments in the parameter pack and that all arguments in the parameter pack have an accessible automatic conversion to CnxFormat via CNX_AS_FORMAT_USER_SUPPLIED_TYPES or have been explicitly converted to CnxFormat already.

#define print(format_string, ...)

Formats the given arguments into the specified format string then prints it to stdout

Parameters
format_string - The format string specifying how text and arguments should be formatted
... - The parameter pack of arguments to format

Formats the arguments according to the given format string, allocating the output string and any intermediaries with the default system allocator. Requires that the number of specifiers in the format string matches the number of arguments in the parameter pack and that all arguments in the parameter pack have an accessible automatic conversion to CnxFormat via CNX_AS_FORMAT_USER_SUPPLIED_TYPES or have been explicitly converted to CnxFormat already.

#define eprint_with_allocator(format_string, allocator, ...)

Formats the given arguments into the specified format string then prints it to stderr

Parameters
format_string - The format string specifying how text and arguments should be formatted
allocator - The allocator to allocate the formatted string with
... - The parameter pack of arguments to format

Formats the arguments according to the given format string, allocating the output string and any intermediaries with the given allocator. Requires that the number of specifiers in the format string matches the number of arguments in the parameter pack and that all arguments in the parameter pack have an accessible automatic conversion to CnxFormat via CNX_AS_FORMAT_USER_SUPPLIED_TYPES or have been explicitly converted to CnxFormat already.

#define eprint(format_string, ...)

Formats the given arguments into the specified format string then prints it to stderr

Parameters
format_string - The format string specifying how text and arguments should be formatted
... - The parameter pack of arguments to format

Formats the arguments according to the given format string, allocating the output string and any intermediaries with the default system allocator. Requires that the number of specifiers in the format string matches the number of arguments in the parameter pack and that all arguments in the parameter pack have an accessible automatic conversion to CnxFormat via CNX_AS_FORMAT_USER_SUPPLIED_TYPES or have been explicitly converted to CnxFormat already.

#define fprintln(file_ptr, format_string, ...)

Formats the given arguments into the specified format string then prints it to the given file, followed by a newline.

Parameters
file_ptr - The file to print the formatted string to
format_string - The format string specifying how text and arguments should be formatted
... - The parameter pack of arguments to format

Formats the arguments according to the given format string, allocating the output string and any intermediaries with the default system allocator. Requires that the number of specifiers in the format string matches the number of arguments in the parameter pack and that all arguments in the parameter pack have an accessible automatic conversion to CnxFormat via CNX_AS_FORMAT_USER_SUPPLIED_TYPES or have been explicitly converted to CnxFormat already.

#define println_with_allocator(format_string, allocator, ...)

Formats the given arguments into the specified format string then prints it to stdout, followed by a newline.

Parameters
format_string - The format string specifying how text and arguments should be formatted
allocator - The allocator to allocate the formatted string with
... - The parameter pack of arguments to format

Formats the arguments according to the given format string, allocating the output string and any intermediaries with the given allocator. Requires that the number of specifiers in the format string matches the number of arguments in the parameter pack and that all arguments in the parameter pack have an accessible automatic conversion to CnxFormat via CNX_AS_FORMAT_USER_SUPPLIED_TYPES or have been explicitly converted to CnxFormat already.

#define println(format_string, ...)

Formats the given arguments into the specified format string then prints it to stdout, followed by a newline.

Parameters
format_string - The format string specifying how text and arguments should be formatted
... - The parameter pack of arguments to format

Formats the arguments according to the given format string, allocating the output string and any intermediaries with the default system allocator. Requires that the number of specifiers in the format string matches the number of arguments in the parameter pack and that all arguments in the parameter pack have an accessible automatic conversion to CnxFormat via CNX_AS_FORMAT_USER_SUPPLIED_TYPES or have been explicitly converted to CnxFormat already.

#define eprintln_with_allocator(format_string, allocator, ...)

Formats the given arguments into the specified format string then prints it to stderr, followed by a newline.

Parameters
format_string - The format string specifying how text and arguments should be formatted
allocator - The allocator to allocate the formatted string with
... - The parameter pack of arguments to format

Formats the arguments according to the given format string, allocating the output string and any intermediaries with the given allocator. Requires that the number of specifiers in the format string matches the number of arguments in the parameter pack and that all arguments in the parameter pack have an accessible automatic conversion to CnxFormat via CNX_AS_FORMAT_USER_SUPPLIED_TYPES or have been explicitly converted to CnxFormat already.

#define eprintln(format_string, ...)

Formats the given arguments into the specified format string then prints it to stderr, followed by a newline.

Parameters
format_string - The format string specifying how text and arguments should be formatted
... - The parameter pack of arguments to format

Formats the arguments according to the given format string, allocating the output string and any intermediaries with the default system allocator. Requires that the number of specifiers in the format string matches the number of arguments in the parameter pack and that all arguments in the parameter pack have an accessible automatic conversion to CnxFormat via CNX_AS_FORMAT_USER_SUPPLIED_TYPES or have been explicitly converted to CnxFormat already.