Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl InstrumentSession {
],
)
.await?;
Ok(root.data.into_iter().map(|d| Run { data: d }).collect())
Ok(root.into_data().map(|d| Run { data: d }).collect())
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ struct Run {
#[Object]
impl Run {
async fn scan_number(&self) -> Option<i64> {
if let NodeAttributes::Container(attr) = &self.data.attributes {
if let NodeAttributes::Container(attr) = &*self.data.attributes {
attr.metadata.start_doc().map(|sd| sd.scan_id)
} else {
None
Expand All @@ -182,16 +182,16 @@ impl Run {
)
.await?;
let mut sources = Vec::new();
for stream in run_data.data {
for stream in run_data.data() {
let stream_data = client
.search(
&format!("{}/{}", self.data.id, stream.id),
headers.clone(),
&[("include_data_sources", "true".into())],
)
.await?;
for dataset in stream_data.data {
match dataset.attributes {
for dataset in stream_data.into_data() {
match *dataset.attributes {
NodeAttributes::Array(attrs) => sources.push(RunData::Array(ArrayData {
run: self,
stream: stream.id.clone(),
Expand Down
39 changes: 35 additions & 4 deletions src/model/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,50 @@ use serde_json::Value;

use crate::model::{array, container, table};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Root {
pub data: Vec<Data>,
data: Vec<DataOption>,
pub error: Value,
pub links: Option<Links>,
pub meta: Value,
}

impl Root {
pub fn data(&self) -> impl Iterator<Item = &Data> {
self.data.iter().flat_map(DataOption::as_data)
}
pub fn into_data(self) -> impl Iterator<Item = Data> {
self.data.into_iter().flat_map(DataOption::into_data)
}
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DataOption {
Data(Data),
Error(Value),
}

impl DataOption {
pub fn as_data(&self) -> Option<&Data> {
match self {
Self::Data(data) => Some(data),
Self::Error(_) => None,
}
}
pub fn into_data(self) -> Option<Data> {
match self {
Self::Data(data) => Some(data),
Self::Error(_) => None,
}
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Data {
pub id: String,
pub attributes: NodeAttributes,
pub links: Links,
pub attributes: Box<NodeAttributes>,
pub links: Box<Links>,
pub meta: Value,
}

Expand Down
Loading