#How to print nested struct of ArrayList ?

1 messages · Page 1 of 1 (latest)

teal oyster
#

Hi guys I have a struct inside a struct and I wonder how to print it so it pretty prints it kind of thing

#

code coming

#

so basically, is there an easy way in Zig to print that

#
const CSSBlock = struct { selectors: std.ArrayList(Selector), body: std.ArrayList([]PropertyValue) };

const AST = struct {
    ast: std.ArrayList(CSSBlock),
};
#

Id like when printing ast to have like

#
{

},

{

}
#

kind of in a JSON manners if that makes any sense ?

#

if that is even possible

earnest cedar
#

youd just loop over the items in the AST arraylist
and then print the items in the selectors and body arraylists and all that

teal oyster
#

title is also wrong I have a struct with an ArrayList with the type of another struct

earnest cedar
#

I dont get what youre confused on

teal oyster
#

I thought thought there would be a method kind of stuff

#

u know JS and console.log printing about anything

#

but ok Ill do this then thx !

earnest cedar
#

you can with the normal print functions
the issue is that it doesnt know the right way to print strings, it can either print them as numbers or characters
and your ArrayLists have an Allocator which would be printed
etc
it would just be really messy

#

and also to make it a lot simpler, it won’t pretty print it, i.e itll all be on one line

#

which makes it pretty much unreadable for stuff like this

normal furnace
#

I think they are asking about the "format" function

teal oyster
#

@normal furnace hmhm probably idk