use std::sync::Arc;
use wp_model_core::model::DataRecord;
mod error;
pub use error::{WparseError, WparseReason, WparseResult};
#[allow(deprecated)]
pub use error::{WplParseError, WplParseReason, WplParseResult};
use wp_model_core::raw::RawData;
pub type DataResult = Result<(DataRecord, RawData), WparseError>;
pub trait PipeProcessor {
fn process(&self, data: RawData) -> WparseResult<RawData>;
fn name(&self) -> &'static str;
}
pub type PipeHold = Arc<dyn PipeProcessor + Send + Sync>;
#[cfg(test)]
mod tests {
use super::RawData;
use bytes::Bytes;
use std::sync::Arc;
#[test]
fn rawdata_as_bytes_and_len_cover_all_variants() {
let text = RawData::from_string("hello");
assert_eq!(text.as_bytes(), b"hello");
assert_eq!(text.len(), 5);
assert!(!text.is_zero_copy());
let bytes = RawData::Bytes(Bytes::from_static(b"bin"));
assert_eq!(bytes.as_bytes(), b"bin");
assert_eq!(bytes.len(), 3);
assert!(bytes.to_bytes().eq(&Bytes::from_static(b"bin")));
assert!(!bytes.is_zero_copy());
let arc = Arc::new(vec![1u8, 2, 3, 4]);
let arc_raw = RawData::from_arc_bytes(arc.clone());
assert_eq!(arc_raw.as_bytes(), arc.as_slice());
assert_eq!(arc_raw.len(), 4);
assert!(arc_raw.is_zero_copy());
let bytes_from_arc = arc_raw.to_bytes();
assert_eq!(bytes_from_arc.as_ref(), &[1, 2, 3, 4]);
let owned = RawData::from_arc_bytes(Arc::new(vec![5u8, 6, 7]));
let converted = owned.into_bytes();
assert_eq!(converted.as_ref(), &[5, 6, 7]);
}
#[test]
fn rawdata_is_empty_handles_all_variants() {
assert!(RawData::from_string("").is_empty());
assert!(RawData::Bytes(Bytes::new()).is_empty());
assert!(RawData::from_arc_bytes(Arc::new(vec![])).is_empty());
assert!(!RawData::from_string("x").is_empty());
}
}