XU XUv0.8.8
中文

API

#encoding/xun

import: #encoding/xun

counts: 3 fns, 36 methods, 1 types, 5 consts, 0 ifaces

XUN documents. parse yields a pooled Doc.

const kind_dict

XuAPI
pub const kind_dict = 0

Purpose

Public constant `kind_dict`. Value `0`.

Parameters

none

const kind_list

XuAPI
pub const kind_list = 1

Purpose

Public constant `kind_list`. Value `1`.

Parameters

none

const kind_scalar

XuAPI
pub const kind_scalar = 2

Purpose

Public constant `kind_scalar`. Value `2`.

Parameters

none

const max_bytes

XuAPI
pub const max_bytes = 1048576

Purpose

Public constant `max_bytes`. Value `1048576`.

Parameters

none

const max_depth

XuAPI
pub const max_depth = 64

Purpose

Public constant `max_depth`. Value `64`.

Parameters

none

struct Doc

XuAPI
pub struct Doc {
    pub kinds []int
    pub tags []string
    pub texts []string
    pub keys []string
    pub firsts []int
    pub nexts []int
    pub lasts []int
    pub root_idx int
    pub err string
    pub line int
    pub lines []string
    pub nos []int
    pub i int
    pub tok_kind int
    pub tok_no int
    pub tok_key string
    pub tok_inline string
}

Purpose

Public struct `Doc`.

Parameters

kinds []int
Tree storage (parallel arrays; node ids index all of them).
tags []string
field ([]string)
texts []string
field ([]string)
keys []string
field ([]string)
firsts []int
field ([]int)
nexts []int
field ([]int)
lasts []int
Child-link bookkeeping during parsing (last child of each node).
root_idx int
field (int)
err string
error
line int
field (int)
lines []string
Parse state (kept here: arrays cannot move between structs).
nos []int
field ([]int)
i int
index or integer
tok_kind int
field (int)
tok_no int
field (int)
tok_key string
field (string)
tok_inline string
field (string)

new_doc

XuAPI
pub fn new_doc() Doc

Purpose

Construct doc.

Parameters

none

Returns

Doc — a value of this type

(Doc) ok

XuAPI
pub fn (d Doc) ok() bool

Purpose

===== public API =====

Parameters

d Doc
receiver Doc (value receiver)

Returns

bool — true or false

(Doc) error

XuAPI
pub fn (d Doc) error() string

Purpose

Call `error` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)

Returns

string — result string

(Doc) error_line

XuAPI
pub fn (d Doc) error_line() int

Purpose

Method on `Doc`: error line.

Parameters

d Doc
receiver Doc (value receiver)

Returns

int — a value of this type

(Doc) root

XuAPI
pub fn (d Doc) root() int

Purpose

Call `root` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)

Returns

int — a value of this type

(Doc) kind

XuAPI
pub fn (d Doc) kind(n int) int

Purpose

Call `kind` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

int — a value of this type

(Doc) is_dict

XuAPI
pub fn (d Doc) is_dict(n int) bool

Purpose

Method on `Doc`: whether it is dict.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) is_list

XuAPI
pub fn (d Doc) is_list(n int) bool

Purpose

Method on `Doc`: whether it is list.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) is_scalar

XuAPI
pub fn (d Doc) is_scalar(n int) bool

Purpose

Method on `Doc`: whether it is scalar.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) tag

XuAPI
pub fn (d Doc) tag(n int) string

Purpose

Call `tag` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

string — result string

(Doc) text

XuAPI
pub fn (d Doc) text(n int) string

Purpose

Method on `Doc`: return the current text.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

string — result string

(Doc) key

XuAPI
pub fn (d Doc) key(n int) string

Purpose

Call `key` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

string — result string

(Doc) count

XuAPI
pub fn (d Doc) count(n int) int

Purpose

Method on `Doc`: count non-overlapping occurrences.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

int — a value of this type

(Doc) at

XuAPI
pub fn (d Doc) at(n int, i int) int

Purpose

Call `at` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)
i int
index or integer (int)

Returns

int — a value of this type

(Doc) get

XuAPI
pub fn (d Doc) get(n int, key string) int

Purpose

Call `get` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)
key string
key (string)

Returns

int — a value of this type

(Doc) as_str

XuAPI
pub fn (d Doc) as_str(n int) string

Purpose

===== typed value accessors =====

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

string — result string

(Doc) as_int

XuAPI
pub fn (d Doc) as_int(n int) int

Purpose

Method on `Doc`: as int.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

int — a value of this type

(Doc) as_f64

XuAPI
pub fn (d Doc) as_f64(n int) f64

Purpose

Method on `Doc`: as f64.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

f64 — a value of this type

(Doc) as_bool

XuAPI
pub fn (d Doc) as_bool(n int) bool

Purpose

Method on `Doc`: as bool.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

bool — true or false

(&mut Doc) set_root

XuAPI
pub fn (d &mut Doc) set_root(r int)

Purpose

===== node construction / tree building API =====

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
r int
rune (Unicode code point) (int)

(&mut Doc) new_node

XuAPI
pub fn (d &mut Doc) new_node(kind int, tag string, text string, key string) int

Purpose

Method on `&mut Doc`: construct node.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
kind int
kind tag (int)
tag string
tag (string)
text string
text (string)
key string
key (string)

Returns

int — a value of this type

(&mut Doc) attach

XuAPI
pub fn (d &mut Doc) attach(parent int, child int)

Purpose

Call `attach` on `&mut Doc`.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
child int
child (int)

(&mut Doc) add_dict

XuAPI
pub fn (d &mut Doc) add_dict(parent int, key string) int

Purpose

Method on `&mut Doc`: add dict.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
key string
key (string)

Returns

int — a value of this type

(&mut Doc) add_list

XuAPI
pub fn (d &mut Doc) add_list(parent int, key string) int

Purpose

Method on `&mut Doc`: add list.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
key string
key (string)

Returns

int — a value of this type

(&mut Doc) add_scalar

XuAPI
pub fn (d &mut Doc) add_scalar(parent int, key string, tag string, text string) int

Purpose

Method on `&mut Doc`: add scalar.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
key string
key (string)
tag string
tag (string)
text string
text (string)

Returns

int — a value of this type

(&mut Doc) add_str

XuAPI
pub fn (d &mut Doc) add_str(parent int, key string, val string) int

Purpose

Method on `&mut Doc`: add str.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
key string
key (string)
val string
value (string)

Returns

int — a value of this type

(&mut Doc) add_int

XuAPI
pub fn (d &mut Doc) add_int(parent int, key string, val int) int

Purpose

Method on `&mut Doc`: add int.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
key string
key (string)
val int
value (int)

Returns

int — a value of this type

(&mut Doc) add_f64

XuAPI
pub fn (d &mut Doc) add_f64(parent int, key string, val f64) int

Purpose

Method on `&mut Doc`: add f64.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
key string
key (string)
val f64
value (f64)

Returns

int — a value of this type

(&mut Doc) add_bool

XuAPI
pub fn (d &mut Doc) add_bool(parent int, key string, val bool) int

Purpose

Method on `&mut Doc`: add bool.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
key string
key (string)
val bool
value (bool)

Returns

int — a value of this type

(&mut Doc) push_dict

XuAPI
pub fn (d &mut Doc) push_dict(parent int) int

Purpose

Method on `&mut Doc`: push dict.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)

Returns

int — a value of this type

(&mut Doc) push_list

XuAPI
pub fn (d &mut Doc) push_list(parent int) int

Purpose

Method on `&mut Doc`: push list.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)

Returns

int — a value of this type

(&mut Doc) push_scalar

XuAPI
pub fn (d &mut Doc) push_scalar(parent int, tag string, text string) int

Purpose

Method on `&mut Doc`: push scalar.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
tag string
tag (string)
text string
text (string)

Returns

int — a value of this type

(&mut Doc) push_str

XuAPI
pub fn (d &mut Doc) push_str(parent int, val string) int

Purpose

Method on `&mut Doc`: push str.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
val string
value (string)

Returns

int — a value of this type

(&mut Doc) push_int

XuAPI
pub fn (d &mut Doc) push_int(parent int, val int) int

Purpose

Method on `&mut Doc`: push int.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
val int
value (int)

Returns

int — a value of this type

(&mut Doc) push_f64

XuAPI
pub fn (d &mut Doc) push_f64(parent int, val f64) int

Purpose

Method on `&mut Doc`: push f64.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
val f64
value (f64)

Returns

int — a value of this type

(&mut Doc) push_bool

XuAPI
pub fn (d &mut Doc) push_bool(parent int, val bool) int

Purpose

Method on `&mut Doc`: push bool.

Parameters

d &mut Doc
receiver &mut Doc (exclusive borrow)
parent int
parent (int)
val bool
value (bool)

Returns

int — a value of this type

parse

XuAPI
pub fn parse(src &string) Doc

Purpose

===== parse =====

Parameters

src &string
source (borrowed; caller keeps it; type &string)

Returns

Doc — a value of this type

encode

XuAPI
pub fn encode(d &Doc) string

Purpose

Encode.

Parameters

d &Doc
d (borrowed; caller keeps it; type &Doc)

Returns

string — result string

(Doc) to_xun

XuAPI
pub fn (d Doc) to_xun() string

Purpose

Method on `Doc`: convert to xun.

Parameters

d Doc
receiver Doc (value receiver)

Returns

string — result string