Struct grafana_plugin_sdk::data::Field[][src]

pub struct Field {
    pub name: String,
    pub labels: BTreeMap<String, String>,
    pub config: Option<FieldConfig>,
    // some fields omitted
}
Expand description

A typed column within a Frame.

The underlying data for this field can be read using the Field::values method, and updated using the Field::set_values and Field::set_values_opt methods.

Fields

name: String

The name of this field.

Fields within a Frame are not required to have unique names, but the combination of name and labels should be unique within a frame to ensure proper behaviour in all situations.

labels: BTreeMap<String, String>

An optional set of key-value pairs that, combined with the name, should uniquely identify a field within a Frame.

config: Option<FieldConfig>

Optional display configuration used by Grafana.

Implementations

Return a new field with the given name.

Example
use grafana_plugin_sdk::prelude::*;

let field = ["a", "b", "c"]
    .into_field("x")
    .with_name("other name");
assert_eq!(&field.name, "other name");

Return a new field with the given labels.

Example
use std::collections::BTreeMap;
use grafana_plugin_sdk::prelude::*;

let mut labels = BTreeMap::default();
labels.insert("some".to_string(), "value".to_string());
let field = ["a", "b", "c"]
    .into_field("x")
    .with_labels(labels);
assert_eq!(field.labels["some"], "value");

Return a new field with the given config.

Example
use grafana_plugin_sdk::{data::FieldConfig, prelude::*};

let field = ["a", "b", "c"]
    .into_field("x")
    .with_config(FieldConfig {
        display_name_from_ds: Some("X".to_string()),
        ..Default::default()
    });
assert_eq!(&field.config.unwrap().display_name_from_ds.unwrap(), "X");

Get the values of this field as a [&dyn Array].

Set the values of this field using an iterator of values.

Errors

Returns an Error::DataTypeMismatch if the types of the new data do not match the types of the existing data.

use arrow2::array::Utf8Array;
use grafana_plugin_sdk::prelude::*;

let mut field = ["a", "b", "c"]
    .into_field("x");
assert!(field.set_values(["d", "e", "f", "g"]).is_ok());
assert_eq!(
    field
        .values()
        .as_any()
        .downcast_ref::<Utf8Array<i32>>()
        .unwrap()
        .iter()
        .collect::<Vec<_>>(),
    vec![Some("d"), Some("e"), Some("f"), Some("g")],
);

assert!(field.set_values([1u32, 2, 3]).is_err());

Set the values of this field using an iterator of optional values.

Errors

Returns an Error::DataTypeMismatch if the types of the new data do not match the types of the existing data.

use arrow2::array::Utf8Array;
use grafana_plugin_sdk::prelude::*;

let mut field = ["a", "b", "c"]
    .into_field("x");
assert!(field.set_values_opt([Some("d"), Some("e"), None, None]).is_ok());
assert_eq!(
    field
        .values()
        .as_any()
        .downcast_ref::<Utf8Array<i32>>()
        .unwrap()
        .iter()
        .collect::<Vec<_>>(),
    vec![Some("d"), Some("e"), None, None],
);

assert!(field.set_values([Some(1u32), Some(2), None]).is_err());

Set the values of this field using an Array.

Errors

Returns an Error::DataTypeMismatch if the types of the new data do not match the types of the existing data.

use arrow2::array::{PrimitiveArray, Utf8Array};
use grafana_plugin_sdk::prelude::*;

let mut field = ["a", "b", "c"]
    .into_field("x");
let new_values = Utf8Array::<i32>::from(["d", "e", "f"].map(Some));
assert!(field.set_values_array(new_values).is_ok());
assert_eq!(
    field
        .values()
        .as_any()
        .downcast_ref::<Utf8Array<i32>>()
        .unwrap()
        .iter()
        .collect::<Vec<_>>(),
    vec![Some("d"), Some("e"), Some("f")],
);

let bad_values = PrimitiveArray::<u32>::from([1, 2, 3].map(Some));
assert!(field.set_values_array(bad_values).is_err());

Trait Implementations

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Wrap the input message T in a tonic::Request

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more