Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make specifier 's' work for struncts to print contained 'strings' as strings. #21334

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jonasdiemer
Copy link

@jonasdiemer jonasdiemer commented Sep 7, 2024

This is an alternative to #21330 to enable "more intuitive" formatting of structs.

Again, please consider it as "request for comment". I find it rather intuitive to be able to format structs as string, with the effect of nested strings being formatted as string.

This is a prototype, works for something like:

const myStruct = struct { name: []const u8, age: u8 };
const s = myStruct{ .name = "Dude", .age = 42 };
std.debug.print("struct: {}\n", .{s});
std.debug.print("struct s: {s}\n", .{s});

which results in

struct: main.myStruct{ .name = { 68, 117, 100, 101 }, .age = 42 }
struct s: main.myStruct{ .name = "Dude", .age = 42 }

If this makes sense to add, I can spend time to make sure to cover all cases, refactor, and add/adjust tests (pointers welcome, this is my first look into zig std lib).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant