From 97047cb95a88228ddefbc83b4c50b05eaf048272 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 29 Nov 2025 15:56:02 -0500 Subject: Update docs --- docs/structs.md | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'docs/structs.md') diff --git a/docs/structs.md b/docs/structs.md index 1dfa49c9..8f280fab 100644 --- a/docs/structs.md +++ b/docs/structs.md @@ -6,10 +6,9 @@ types that can be accessed by fields: ```tomo struct Foo(name:Text, age:Int) ... ->> my_foo := Foo("Bob", age=10) -= Foo(name="Bob", age=10) ->> my_foo.name -= "Bob" +my_foo := Foo("Bob", age=10) +assert my_foo == Foo(name="Bob", age=10) +assert my_foo.name == "Bob" ``` Structs are value types and comparisons on them operate on the member values @@ -49,11 +48,8 @@ struct Password(raw_password_text:Text; secret) struct User(username:Text, password:Password) ... user := User("Stanley", Password("Swordfish")) ->> user -= User(username="Stanley", password=Password(...)) - ->> "$user" == 'User(username="Stanley", password=Password(...))' -= yes +assert user == User("Stanley", Password("Swordfish")) +assert "You are: $user" == 'You are: User(username="Stanley", password=Password(...))' ``` Designing APIs so they take secrecy-protected structs instead of raw data @@ -62,17 +58,12 @@ your logs! Secrecy-protected values still work the same as any other struct, they just don't divulge their contents when converting to strings: ```tomo ->> user.password == Password("Swordfish") -= yes +assert user.password == Password("Swordfish") ``` You can also access the fields directly, but hopefully this extra amount of friction reduces the chances of accidentally divulging sensitive content: ```tomo ->> user.password -= Password(...) - ->> user.password.raw_password_text -= "Swordfish" +assert user.password.raw_password_text == "Swordfish" ``` -- cgit v1.2.3