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

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

View File

@ -3,6 +3,7 @@ mod addition;
mod calculation;
mod message;
mod query;
mod reply;
mod request_data;
mod user;
@ -12,5 +13,6 @@ pub use addition::Addition;
pub use calculation::{CalcValue, Calculation, Operand};
pub use message::MsgAction;
pub use query::Query;
pub use reply::Reply;
use request_data::RequestData;
pub use user::UserAction;

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>,
{

View File

@ -1,11 +1,11 @@
use super::{InternalRecord, InternalRecords, Oid};
use crate::{
action::{Action, CalcValue, Calculation, MsgAction, Query, Records},
action::{Action, CalcValue, Calculation, MsgAction, Query, Records, Reply},
document::{
definition::{DocDef, DocFuncType},
field::Field,
},
message::wrapper::{Message, Reply, Update},
message::wrapper::{Message, Update},
mtterror::{ErrorID, MTTError},
name::NameType,
queue::{

View File

@ -1,5 +1,5 @@
use crate::{
action::{CalcValue, Field, FieldType, MsgAction, Operand, Query},
action::{CalcValue, Field, FieldType, MsgAction, Operand, Query, Reply},
mtterror::{ErrorID, MTTError},
name::{NameType, Names},
queue::data_director::{Include, Path, Route},
@ -266,6 +266,7 @@ impl Operation {
}
}
/*
#[allow(dead_code)]
#[derive(Clone, Debug)]
pub struct Reply {
@ -345,6 +346,7 @@ mod replies {
}
}
}
*/
#[derive(Clone, Debug)]
pub struct Document {