powered by

FTD

list

list keyword can be used to create a list or an array in ftd.

Declaring a list

a list of integer

-- integer list primes:

Here we have declared a new variable called primes, which is a list of integers. When the list is created it is empty.

Note: By default, lists are immutable. The user can make the list mutable by prefixing it with $ like this -- integer list $primes:

Initializing values to a list

We can add elements to the list during initialization by mentioning the list-type like this:

-- <list-type>: <value>.

Note: Also make sure to use the end syntax -- end: <list-name> to mark the end of the list during initialization.

-- integer list primes:

-- integer: 1
-- integer: 3
-- integer: 5
-- integer: 7
-- integer: 11

-- end: primes

We have inserted 5 integers to our list named primes.

-- record person:
caption name:
body bio:

-- person list people:

-- person: Amit Upadhyay

Amit is CEO of FifthTry.

-- person: Shobhit Sharma

Shobhit is a developer at FifthTry.

-- end: people

Here we have created a list of person objects, called it people, and created two person objects and inserted them the people list.

$processor$

A list can be created using platform provided processors:

-- string list foo:
$processor$: some-list

Here the value of the list will be provided by the some-list processor.

If we already have a list we can insert values to it using $processor$ as well:

-- string list foo:

-- foo:
$processor$: some-list

Reading A list from Rust

You can use the .get() method to read a list:

#[derive(serde::Deserialize)]
struct Person {
    name: String,
    bio: String,
}

let doc = ftd::p2::Document::from("some/id", source, lib)?;
let people: Vec<Person> = doc.get("people")?;

You can read more details of reading ftd files “Reading FTD Files” guide.

FTD

list

list keyword can be used to create a list or an array in ftd.

Declaring a list

a list of integer

-- integer list primes:

Here we have declared a new variable called primes, which is a list of integers. When the list is created it is empty.

Note: By default, lists are immutable. The user can make the list mutable by prefixing it with $ like this -- integer list $primes:

Initializing values to a list

We can add elements to the list during initialization by mentioning the list-type like this:

-- <list-type>: <value>.

Note: Also make sure to use the end syntax -- end: <list-name> to mark the end of the list during initialization.

-- integer list primes:

-- integer: 1
-- integer: 3
-- integer: 5
-- integer: 7
-- integer: 11

-- end: primes

We have inserted 5 integers to our list named primes.

-- record person:
caption name:
body bio:

-- person list people:

-- person: Amit Upadhyay

Amit is CEO of FifthTry.

-- person: Shobhit Sharma

Shobhit is a developer at FifthTry.

-- end: people

Here we have created a list of person objects, called it people, and created two person objects and inserted them the people list.

$processor$

A list can be created using platform provided processors:

-- string list foo:
$processor$: some-list

Here the value of the list will be provided by the some-list processor.

If we already have a list we can insert values to it using $processor$ as well:

-- string list foo:

-- foo:
$processor$: some-list

Reading A list from Rust

You can use the .get() method to read a list:

#[derive(serde::Deserialize)]
struct Person {
    name: String,
    bio: String,
}

let doc = ftd::p2::Document::from("some/id", source, lib)?;
let people: Vec<Person> = doc.get("people")?;

You can read more details of reading ftd files “Reading FTD Files” guide.