1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

doc: use u8 instead of byte

This commit is contained in:
Alexander Medvednikov 2023-05-18 12:24:00 +02:00
parent cc47c78f39
commit f67952fe84
2 changed files with 14 additions and 13 deletions

View File

@ -7,6 +7,7 @@
- Enum values now can have attributes. - Enum values now can have attributes.
- json: Enum value string serialization supports `[json:'alias']` to change its string values. - json: Enum value string serialization supports `[json:'alias']` to change its string values.
- Functions can now return fixed size arrays. - Functions can now return fixed size arrays.
- The builtin websocket library is now thread safe.
## V 0.3.4 ## V 0.3.4

View File

@ -558,7 +558,7 @@ assert s.len == 10
arr := s.bytes() // convert `string` to `[]u8` arr := s.bytes() // convert `string` to `[]u8`
assert arr.len == 10 assert arr.len == 10
s2 := arr.bytestr() // convert `[]byte` to `string` s2 := arr.bytestr() // convert `[]u8` to `string`
assert s2 == s assert s2 == s
``` ```
@ -571,9 +571,9 @@ s[0] = `H` // not allowed
> error: cannot assign to `s[i]` since V strings are immutable > error: cannot assign to `s[i]` since V strings are immutable
Note that indexing a string will produce a `byte`, not a `rune` nor another `string`. Indexes Note that indexing a string will produce a `u8` (byte), not a `rune` nor another `string`. Indexes
correspond to _bytes_ in the string, not Unicode code points. If you want to convert the `byte` to a correspond to _bytes_ in the string, not Unicode code points. If you want to convert the `u8` to a
`string`, use the `.ascii_str()` method on the `byte`: `string`, use the `.ascii_str()` method on the `u8`:
```v ```v
country := 'Netherlands' country := 'Netherlands'
@ -2559,10 +2559,10 @@ Just like structs, unions support embedding.
```v ```v
struct Rgba32_Component { struct Rgba32_Component {
r byte r u8
g byte g u8
b byte b u8
a byte a u8
} }
union Rgba32 { union Rgba32 {
@ -3515,12 +3515,12 @@ Interfaces support embedding, just like structs:
```v ```v
pub interface Reader { pub interface Reader {
mut: mut:
read(mut buf []byte) ?int read(mut buf []u8) ?int
} }
pub interface Writer { pub interface Writer {
mut: mut:
write(buf []byte) ?int write(buf []u8) ?int
} }
// ReaderWriter embeds both Reader and Writer. // ReaderWriter embeds both Reader and Writer.
@ -5955,7 +5955,7 @@ Since V does not support overloading functions by intention there are wrapper fu
C headers named `atomic.h` that are part of the V compiler infrastructure. C headers named `atomic.h` that are part of the V compiler infrastructure.
There are dedicated wrappers for all unsigned integer types and for pointers. There are dedicated wrappers for all unsigned integer types and for pointers.
(`byte` is not fully supported on Windows) – the function names include the type name (`u8` is not fully supported on Windows) – the function names include the type name
as suffix. e.g. `C.atomic_load_ptr()` or `C.atomic_fetch_add_u64()`. as suffix. e.g. `C.atomic_load_ptr()` or `C.atomic_fetch_add_u64()`.
To use these functions the C header for the used OS has to be included and the functions To use these functions the C header for the used OS has to be included and the functions
@ -6393,7 +6393,7 @@ These can be converted to V strings with `string_from_wide(&u16(cwidestring))` .
V has these types for easier interoperability with C: V has these types for easier interoperability with C:
- `voidptr` for C's `void*`, - `voidptr` for C's `void*`,
- `&byte` for C's `byte*` and - `&u8` for C's `byte*` and
- `&char` for C's `char*`. - `&char` for C's `char*`.
- `&&char` for C's `char**` - `&&char` for C's `char**`
@ -6431,7 +6431,7 @@ members of sub-data-structures may be directly declared in the containing struct
```v ```v
struct C.SomeCStruct { struct C.SomeCStruct {
implTraits byte implTraits u8
memPoolData u16 memPoolData u16
// These members are part of sub data structures that can't currently be represented in V. // These members are part of sub data structures that can't currently be represented in V.
// Declaring them directly like this is sufficient for access. // Declaring them directly like this is sufficient for access.