-
Notifications
You must be signed in to change notification settings - Fork 373
Add a generated stringification method #580
Copy link
Copy link
Closed
Labels
Description
I'd like to add the ability for cbindgen to generate a stringifier for enums and structs. It could be controlled by a derive-ostream option similar to derive-eq and friends. For enums it would generate something like:
std::ostream& operator<<(std::ostream& aStream, const MyEnum& aEnum) {
switch (aEnum) {
case One:
aStream << "One";
break;
...
}
return aStream;
}
and for structs it would do something like this:
struct MyStruct {
int x;
int y;
...
friend std::ostream& operator<<(std::ostream& aStream, const MyStruct& aStruct) {
return aStream << "{ x=" << aStruct.x << ", y=" << aStruct.y << " }";
}
...
};
Any objections/suggestions? The goal here is to remove the hand-written stuff that we have in m-c as part of bug the cleanup I'm doing in bug 1666802 and friends.
Reactions are currently unavailable