Moved Record into document module.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
parent
404c6e9c34
commit
920c2da38f
@ -1,8 +1,39 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
message::wrapper::{InternalRecord, InternalRecords, Oid, Record},
|
action::Field,
|
||||||
name::{Name, Names},
|
message::wrapper::{InternalRecord, InternalRecords, Oid},
|
||||||
|
mtterror::{ErrorID, MTTError},
|
||||||
|
name::{Name, NameType, Names},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Record {
|
||||||
|
names: Names,
|
||||||
|
data: InternalRecord,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Record {
|
||||||
|
pub fn with_data(names: Names, rec: InternalRecord) -> Self {
|
||||||
|
Self {
|
||||||
|
names: names,
|
||||||
|
data: rec,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get<NT>(&self, field_id: NT) -> Result<Field, MTTError>
|
||||||
|
where
|
||||||
|
NT: Into<NameType>,
|
||||||
|
{
|
||||||
|
let id = match self.names.get_id(field_id) {
|
||||||
|
Ok(data) => data,
|
||||||
|
Err(err) => return Err(err),
|
||||||
|
};
|
||||||
|
match self.data.get(&id) {
|
||||||
|
Some(data) => Ok(data.clone()),
|
||||||
|
None => Err(MTTError::new(NameType::None, ErrorID::FieldMissingData)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Records {
|
pub struct Records {
|
||||||
names: Names,
|
names: Names,
|
||||||
|
|||||||
@ -441,99 +441,7 @@ impl InternalRecords {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Record {
|
|
||||||
names: Names,
|
|
||||||
data: InternalRecord,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Record {
|
|
||||||
pub fn with_data(names: Names, rec: InternalRecord) -> Self {
|
|
||||||
Self {
|
|
||||||
names: names,
|
|
||||||
data: rec,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get<NT>(&self, field_id: NT) -> Result<Field, MTTError>
|
|
||||||
where
|
|
||||||
NT: Into<NameType>,
|
|
||||||
{
|
|
||||||
let id = match self.names.get_id(field_id) {
|
|
||||||
Ok(data) => data,
|
|
||||||
Err(err) => return Err(err),
|
|
||||||
};
|
|
||||||
match self.data.get(&id) {
|
|
||||||
Some(data) => Ok(data.clone()),
|
|
||||||
None => Err(MTTError::new(NameType::None, ErrorID::FieldMissingData)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Records {
|
|
||||||
names: Names,
|
|
||||||
data: InternalRecords,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Records {
|
|
||||||
pub fn new(names: Names) -> Self {
|
|
||||||
Self {
|
|
||||||
names: names,
|
|
||||||
data: InternalRecords::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_data(names: Names, records: InternalRecords) -> Self {
|
|
||||||
Self {
|
|
||||||
names: names,
|
|
||||||
data: records,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert(&mut self, oid: Oid, record: InternalRecord) -> Option<InternalRecord> {
|
|
||||||
self.data.insert(oid, record)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
|
||||||
self.data.len()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn iter(&self) -> impl Iterator<Item = Record> {
|
|
||||||
RecordIter::new(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_internal_records(&self) -> &InternalRecords {
|
|
||||||
&self.data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct RecordIter {
|
|
||||||
names: Names,
|
|
||||||
recs: Vec<InternalRecord>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RecordIter {
|
|
||||||
fn new(records: &Records) -> Self {
|
|
||||||
Self {
|
|
||||||
names: records.names.clone(),
|
|
||||||
recs: records.data.values().cloned().collect(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Iterator for RecordIter {
|
|
||||||
type Item = Record;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
match self.recs.pop() {
|
|
||||||
Some(rec) => Some(Record::with_data(self.names.clone(), rec.clone())),
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Document {
|
pub struct Document {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user