aboutsummaryrefslogtreecommitdiff
path: root/docs/structs.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/structs.md')
-rw-r--r--docs/structs.md23
1 files changed, 7 insertions, 16 deletions
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"
```