Moved reply into action.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s

This commit is contained in:
2026-02-14 13:04:55 -05:00
parent 1a06794265
commit 1f82c07565
6 changed files with 89 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
use super::{Addition, DocDef, Query, Records, UserAction};
use super::{Addition, DocDef, Query, Records, Reply, UserAction};
use crate::{
message::{
wrapper::{Delete, Reply, Update},
wrapper::{Delete, Update},
MessageAction,
},
mtterror::MTTError,

79
src/action/reply.rs Normal file
View File

@@ -0,0 +1,79 @@
use super::{CalcValue, RequestData};
#[derive(Clone, Debug)]
pub struct Reply {
data: Vec<RequestData>,
}
impl Reply {
pub fn new() -> Self {
Self { data: Vec::new() }
}
fn add(&mut self, doc: RequestData) {
self.data.push(doc);
}
pub fn len(&self) -> usize {
self.data.len()
}
fn iter(&self) -> impl Iterator<Item = &RequestData> {
self.data.iter()
}
}
#[cfg(test)]
mod replies {
use super::*;
use crate::{action::Field, name::Name};
#[test]
fn is_new_empty() {
let reply = Reply::new();
assert_eq!(reply.len(), 0, "should have no records");
}
#[test]
fn can_add_documents() {
let mut reply = Reply::new();
let doc = RequestData::new();
reply.add(doc.clone());
assert_eq!(reply.len(), 1);
reply.add(doc.clone());
assert_eq!(reply.len(), 2);
}
#[test]
fn can_retrieve_documents() {
let fieldname = Name::english("field");
let mut doc1 = RequestData::new();
doc1.add_field(fieldname.clone(), "one");
let mut doc2 = RequestData::new();
doc2.add_field(fieldname.clone(), "two");
let mut reply = Reply::new();
reply.add(doc1);
reply.add(doc2);
let mut reply_iter = reply.iter();
let result1 = reply_iter.next().unwrap();
match result1.get_field(&fieldname) {
CalcValue::Value(data) => match data {
Field::StaticString(output) => assert_eq!(output, "one"),
_ => unreachable!("got {:?}: should have been static string", result1),
},
_ => unreachable!("got {:?}, should have been value", result1),
}
let result2 = reply_iter.next().unwrap();
match result2.get_field(&fieldname) {
CalcValue::Value(data) => match data {
Field::StaticString(output) => assert_eq!(output, "two"),
_ => unreachable!("got {:?}: should have been static string", result2),
},
_ => unreachable!("got {:?}, should have been value", result2),
}
match reply_iter.next() {
None => {}
Some(_) => unreachable!("should be out of data"),
}
}
}

View File

@@ -24,7 +24,7 @@ impl RequestData {
self.data.insert(name.into(), field.into());
}
fn get_field<NT>(&self, name: NT) -> &CalcValue
pub fn get_field<NT>(&self, name: NT) -> &CalcValue
where
NT: Into<NameType>,
{