Skip to content

Commit a6b5924

Browse files
committed
feat: implement to_str for array
1 parent cc36ca3 commit a6b5924

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

libdestruct/common/array/array_impl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def to_bytes(self: array_impl) -> bytes:
5757
"""Return the serialized representation of the array."""
5858
return b"".join(bytes(x) for x in self)
5959

60+
def to_str(self: array_impl, indent: int = 0) -> str:
61+
"""Return the string representation of the array."""
62+
return "[" + ", ".join(x.to_str(indent) for x in self) + "]"
63+
6064
def __setitem__(self: array_impl, index: int, value: obj) -> None:
6165
"""Set an item in the array."""
6266
raise NotImplementedError("Cannot set items in an array.")

0 commit comments

Comments
 (0)