coap-handler-implementations 0.6.2

Simple implementations of CoAP handlers
Documentation
#!/usr/bin/env python3

import itertools

out = open(__file__.replace(".py", ".rs"), "w")
write = lambda *args: print(*args, file=out)
write(f"// Generated by {__file__}")
write(f"#![cfg_attr(rustfmt, rustfmt_skip)]")

methods = ['Get', 'Post', 'Put', 'Delete', 'Fetch', 'IPatch']
associated_types = {
        "Get": ["Get"],
        "Post": ["PostIn", "PostOut"],
        "Put": ["Put"],
        "Delete": [],
        "Fetch": ["FetchIn", "FetchOut"],
        "IPatch": ["IPatch"],
}

for count in range(1, len(methods)):
    for implemented in itertools.combinations(methods, count):
        with_name = "with_" + "_".join(implemented).lower()
        requirements = "\n".join(f"    T: super::{i}Renderable," for i in implemented)
        filled = set(methods) - set(implemented)
        result = "renderable"
        guarantees = []
        for i in implemented:
            for at in associated_types[i]:
                guarantees.append(f"{at} = T::{at}")
        for f in filled:
            result = f"super::fillers::Fill{f}({result})"
            for at in associated_types[f]:
                guarantees.append(f"{at} = ()")
        write(f"pub fn {with_name}<T>(renderable: T) -> impl super::TypeRenderable<{', '.join(guarantees)}>")
        write("where")
        write(requirements)
        write("{")
        write(f"    {result}")
        write("}")