# Assets

An [asset](https://dev.nominal.io/platform/data-model.md#asset) is a system you test, such as a vehicle or a test stand. It helps organize and label the data and videos you add to Nominal.

The examples on this page use a quadcopter as an example, but the asset can represent any physical or conceptual device. To decide what an asset represents in your tests, see [Organize and view your data](https://dev.nominal.io/platform/data-model/paradigms.md).

To use this page, first make sure you can [Connect to Nominal](https://dev.nominal.io/rust-client/guides/connect.md) and obtain a `client`.

## Create an asset

```rust
use nominal::core::AssetCreate;

let asset = client
    .assets()
    .create(
        AssetCreate::new("Quadcopter 456")
            .description("Airborne observation platform")
            .properties([("serial", "QC-456")]) // identify the physical system
            .labels(["camera", "airborne"]), // group assets for searching
    )
    .await?;
println!("{}", asset.nominal_url());
```

[`create`](https://dev.nominal.io/rust-client/ref/rust/nominal/core/struct.AssetsClient.md#method.create "nominal::core::AssetsClient::create") always makes a new asset even if another asset has the same name. [Fetch the asset](https://dev.nominal.io/rust-client/guides/assets.md#fetch-assets) if you know the [RID](https://dev.nominal.io/platform/reference/glossary.md#rid) or [search](https://dev.nominal.io/rust-client/guides/assets.md#find-assets) first if you want to re-use an existing asset but don’t have the RID saved.

## Fetch assets

If the RID of an asset is known, you can fetch that asset directly without needing to search.

```rust
let asset = client.assets().get("<ri.scout.instance.asset.identifier>").await?;
```

## Find assets

[`search`](https://dev.nominal.io/rust-client/ref/rust/nominal/core/struct.AssetsClient.md#method.search "nominal::core::AssetsClient::search") finds assets by label, property or name. Combine filters with [`and`](https://dev.nominal.io/rust-client/ref/rust/nominal/core/enum.AssetQuery.md#method.and "nominal::core::AssetQuery::and") and [`or`](https://dev.nominal.io/rust-client/ref/rust/nominal/core/enum.AssetQuery.md#method.or "nominal::core::AssetQuery::or"):

```rust
use nominal::core::AssetQuery;

// Every asset, newest first
let assets = client.assets().list().await?;

// Names that contain "quadcopter", in any case
let assets = client.assets().search(AssetQuery::substring_match("quadcopter")).await?;

// The "airborne" label and the serial QC-456, both
let assets = client
    .assets()
    .search(AssetQuery::and([AssetQuery::label("airborne"), AssetQuery::property("serial", "QC-456")]))
    .await?;
```

## Attach data to the asset

A [data scope](https://dev.nominal.io/platform/data-model.md#data-scopes-and-ref-names) adds a dataset to an asset under a ref name, such as `default`.

```rust
client.assets().add_dataset(asset.rid(), "default", "<ri.catalog.instance.dataset.identifier>").await?;
```

When using the [tagged approach](https://dev.nominal.io/platform/data-model/organization/tagged-data.md), filter a single shared dataset using the tags unique to your asset with [`add_dataset_with_tags`](https://dev.nominal.io/rust-client/ref/rust/nominal/core/struct.AssetsClient.md#method.add_dataset_with_tags "nominal::core::AssetsClient::add_dataset_with_tags")

```rust
// the example asset is uniquely identified by the tag vehicle=QC-456
client
    .assets()
    .add_dataset_with_tags(asset.rid(), "default", "<ri.catalog.instance.dataset.identifier>", [("vehicle", "QC-456")])
    .await?;
```

[`add_data_sources`](https://dev.nominal.io/rust-client/ref/rust/nominal/core/struct.AssetsClient.md#method.add_data_sources "nominal::core::AssetsClient::add_data_sources") adds several datasets and videos at once.

```rust
use nominal::core::DataSource;

client
    .assets()
    .add_data_sources(
        asset.rid(),
        [
            ("default", DataSource::dataset("<ri.catalog.instance.dataset.identifier>")),
            ("nose-camera", DataSource::video("<ri.video.instance.video.identifier>")),
        ],
    )
    .await?;
```

## Update an asset

[`update`](https://dev.nominal.io/rust-client/ref/rust/nominal/core/struct.AssetsClient.md#method.update "nominal::core::AssetsClient::update") changes the fields you include in the asset update request by overwriting those fields. That is, `update(labels)` will *not* touch properties, but it *will* overwrite the current set of labels with the ones you provide.

```rust
use nominal::core::AssetUpdate;

// The labels you set replace the asset's labels, so start from its current ones
let mut labels = asset.labels().to_vec();
labels.push("new-motor-vendor".to_string());
let asset = client.assets().update(asset.rid(), AssetUpdate::new().labels(labels)).await?;
```

## Archive an asset

[`archive`](https://dev.nominal.io/rust-client/ref/rust/nominal/core/struct.AssetsClient.md#method.archive "nominal::core::AssetsClient::archive") hides an asset from the UI and from searches, without deleting it. [`unarchive`](https://dev.nominal.io/rust-client/ref/rust/nominal/core/struct.AssetsClient.md#method.unarchive "nominal::core::AssetsClient::unarchive") brings it back.

```rust
client.assets().archive(asset.rid()).await?;
```
