Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
str as_bytes doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-000 committed Aug 20, 2023
1 parent d6b99f8 commit 28eec20
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/language_concepts/00_data_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ fn main(message : pub str<11>, hex_as_string : str<4>) {
}
```

You can convert a `str<N>` to a byte array by calling `as_bytes()`
or a vector by calling `as_bytes_vec()`.

```rust
fn main() {
let message = "hello world";
let message_bytes = message.as_bytes();
let mut message_vec = message.as_bytes_vec();
assert(message_bytes.len() == 11);
assert(message_bytes[0] == 104);
assert(message_bytes[0] == message_vec.get(0));
}
```

## Compound Types

A compound type groups together multiple values into one type. Elements within a compound type can
Expand Down

0 comments on commit 28eec20

Please sign in to comment.