script API

← script · version 0.4.0

11 public items, in source order. Generated from the registry index, which re-derives them from the package source at publish time — so a signature here is the one that version actually ships.

pub fn walk(self: text, suffix: text = "", links: boolean = true) -> iterator<text>

The files under the directory self, in every subdirectory, one at a time as a for loop asks for them: for p in "src".walk(".rs") { … }. Nothing is listed before the loop reaches it and nothing is sorted: each directory gives its files in name order, then its subdirectories are walked the same way, depth first. suffix keeps only the names that end with it (".loft"); "" keeps every file. A path that is not a directory gives no files. Use [walk_sorted] when the order matters.

A symbolic link to a DIRECTORY is never entered, so a loop in the tree is not a loop here. A link to a FILE is given like any file, as find and Python's os.walk do; links: false leaves it out, at the cost of one more check per file given. A library placed out of process should hand its callers walk_sorted, the whole answer in one value, rather than one crossing per file.

pub fn walk_sorted(self: text, suffix: text = "", links: boolean = true) -> vector<text>

The files [walk] gives, as one vector in path order — the same files, at the cost of listing them all before the first is used, and of the sort. walk_sorted(suffix, links: false) is the walk of 0.2 and before, which never gave a linked file.

pub fn copy_to(self: text, dst: text) -> boolean

Copy the file at self to dst, bytes as they are: true when dst now holds them. A source that cannot be read writes nothing and answers false, as does a write that fails.

pub fn glob(self: text) -> vector<text>

The paths that match the pattern self, in name order: * stands for any run of characters inside one name, ? for one character, and everything before the last / is a directory taken as written ("default/*.loft", "out/??.txt"). A pattern without a / is matched against the current directory. An absent directory answers no paths.

pub fn glob_match(pattern: text, name: text) -> boolean

Does name match pattern, with * any run and ? one character? A plain character matches itself only. A name that starts with . matches only a pattern that starts with ., as a shell's and Python's glob have it: *.loft is not .loft, a hidden entry.

pub struct Word { key: text }

One element of a set of texts: the text is the key.

pub fn set(words: vector<text>) -> sorted<Word[key]>

A set of the texts in words: each once, in key order. set([]) is the empty set.

pub fn has(self: sorted<Word[key]>, w: text) -> boolean

Is w in the set?

pub fn put(self: sorted<Word[key]>, w: text)

Put w in the set; a text already there stays once.

pub fn minus(self: sorted<Word[key]>, other: sorted<Word[key]>) -> vector<text>

The texts of self that are not in other, in key order.

pub fn words(self: sorted<Word[key]>) -> vector<text>

The texts of the set as a vector, in key order.