docs: document more `builtin` functions/methods (#14229)
parent
bbd015a327
commit
1ad84bb2d1
|
@ -22,7 +22,7 @@ fn main() {
|
||||||
mut a := i64(0)
|
mut a := i64(0)
|
||||||
mut b := i64(0)
|
mut b := i64(0)
|
||||||
mut c := i64(1)
|
mut c := i64(1)
|
||||||
println(a + c + c)
|
println(a + b + c)
|
||||||
for _ in 0 .. stop {
|
for _ in 0 .. stop {
|
||||||
// Set a and b to the next term
|
// Set a and b to the next term
|
||||||
a = b
|
a = b
|
||||||
|
|
|
@ -64,6 +64,7 @@ fn panic_debug(line_no int, file string, mod string, fn_name string, s string) {
|
||||||
vhalt()
|
vhalt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// panic_optional_not_set prints given optional not set and exits the process
|
||||||
[noreturn]
|
[noreturn]
|
||||||
pub fn panic_optional_not_set(s string) {
|
pub fn panic_optional_not_set(s string) {
|
||||||
panic('optional not set ($s)')
|
panic('optional not set ($s)')
|
||||||
|
|
|
@ -17,14 +17,17 @@ pub fn ptr_str(ptr voidptr) string {
|
||||||
return buf1
|
return buf1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// str returns string equivalent of x
|
||||||
pub fn (x isize) str() string {
|
pub fn (x isize) str() string {
|
||||||
return i64(x).str()
|
return i64(x).str()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// str returns string equivalent of x
|
||||||
pub fn (x usize) str() string {
|
pub fn (x usize) str() string {
|
||||||
return u64(x).str()
|
return u64(x).str()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// str returns string equivalent of cptr
|
||||||
pub fn (cptr &char) str() string {
|
pub fn (cptr &char) str() string {
|
||||||
return u64(cptr).hex()
|
return u64(cptr).hex()
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ pub interface IError {
|
||||||
code() int
|
code() int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// str returns the message of IError
|
||||||
pub fn (err IError) str() string {
|
pub fn (err IError) str() string {
|
||||||
return match err {
|
return match err {
|
||||||
None__ {
|
None__ {
|
||||||
|
@ -50,10 +51,12 @@ pub fn (err IError) str() string {
|
||||||
// Error is the empty default implementation of `IError`.
|
// Error is the empty default implementation of `IError`.
|
||||||
pub struct Error {}
|
pub struct Error {}
|
||||||
|
|
||||||
|
// msg returns the message of Error
|
||||||
pub fn (err Error) msg() string {
|
pub fn (err Error) msg() string {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// code returns the code of Error
|
||||||
pub fn (err Error) code() int {
|
pub fn (err Error) code() int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -65,10 +68,12 @@ pub:
|
||||||
code int
|
code int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// msg returns the message of the MessageError
|
||||||
pub fn (err MessageError) msg() string {
|
pub fn (err MessageError) msg() string {
|
||||||
return err.msg
|
return err.msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// code returns the code of MessageError
|
||||||
pub fn (err MessageError) code() int {
|
pub fn (err MessageError) code() int {
|
||||||
return err.code
|
return err.code
|
||||||
}
|
}
|
||||||
|
@ -88,6 +93,7 @@ pub struct Option {
|
||||||
err IError = none__
|
err IError = none__
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// str returns the Option type: ok, none, or error
|
||||||
pub fn (o Option) str() string {
|
pub fn (o Option) str() string {
|
||||||
if o.state == 0 {
|
if o.state == 0 {
|
||||||
return 'Option{ ok }'
|
return 'Option{ ok }'
|
||||||
|
|
|
@ -13,6 +13,7 @@ pub interface IError {
|
||||||
code() int
|
code() int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// str returns the message of IError
|
||||||
pub fn (err IError) str() string {
|
pub fn (err IError) str() string {
|
||||||
return match err {
|
return match err {
|
||||||
None__ {
|
None__ {
|
||||||
|
@ -52,10 +53,12 @@ pub:
|
||||||
code int
|
code int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// msg returns the message of MessageError
|
||||||
pub fn (err MessageError) msg() string {
|
pub fn (err MessageError) msg() string {
|
||||||
return err.msg
|
return err.msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// code returns the code of MessageError
|
||||||
pub fn (err MessageError) code() int {
|
pub fn (err MessageError) code() int {
|
||||||
return err.code
|
return err.code
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ pub mut:
|
||||||
delimiter u8
|
delimiter u8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// new_writer returns a reference to a Writer
|
||||||
pub fn new_writer() &Writer {
|
pub fn new_writer() &Writer {
|
||||||
return &Writer{
|
return &Writer{
|
||||||
delimiter: `,`
|
delimiter: `,`
|
||||||
|
@ -75,6 +76,7 @@ fn (w &Writer) field_needs_quotes(field string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// str returns the writer contents
|
||||||
pub fn (mut w Writer) str() string {
|
pub fn (mut w Writer) str() string {
|
||||||
return w.sb.str()
|
return w.sb.str()
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,12 @@ mut:
|
||||||
failed bool
|
failed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validate_str reports if str consists of valid UTF-8 runes
|
||||||
pub fn validate_str(str string) bool {
|
pub fn validate_str(str string) bool {
|
||||||
return validate(str.str, str.len)
|
return validate(str.str, str.len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validate reports if data consists of valid UTF-8 runes
|
||||||
pub fn validate(data &u8, len int) bool {
|
pub fn validate(data &u8, len int) bool {
|
||||||
mut state := Utf8State{}
|
mut state := Utf8State{}
|
||||||
for i := 0; i < len; i++ {
|
for i := 0; i < len; i++ {
|
||||||
|
|
|
@ -85,6 +85,7 @@ const tokens_3 = ['MMM', 'DDD', 'ZZZ', 'ddd']
|
||||||
const tokens_4 = ['MMMM', 'DDDD', 'DDDo', 'dddd', 'YYYY']
|
const tokens_4 = ['MMMM', 'DDDD', 'DDDo', 'dddd', 'YYYY']
|
||||||
|
|
||||||
// custom_format returns a date with custom format
|
// custom_format returns a date with custom format
|
||||||
|
//
|
||||||
// | | Token | Output |
|
// | | Token | Output |
|
||||||
// | :----------- | -------: | :--------- |
|
// | :----------- | -------: | :--------- |
|
||||||
// | Month | M | 1 2 ... 11 12 |
|
// | Month | M | 1 2 ... 11 12 |
|
||||||
|
|
Loading…
Reference in New Issue