Owned items, static values
Some checks failed
CI / Typos (push) Failing after 20s
CI / Build and test (push) Failing after 2m17s
CI / Clippy (push) Failing after 3m27s
CI / Build and test (all features) (push) Failing after 5m56s

This commit is contained in:
2026-03-10 21:05:51 -07:00
parent 48ac93c78e
commit bfa67994bf
20 changed files with 304 additions and 378 deletions

View File

@@ -1,24 +1,27 @@
use epub::doc::EpubDoc;
use pile_config::Label;
use std::{collections::HashMap, sync::OnceLock};
use std::{
collections::HashMap,
sync::{Arc, OnceLock},
};
use tracing::trace;
use crate::{Item, PileValue, SyncReadBridge, extract::ObjectExtractor};
pub struct EpubMetaExtractor<'a> {
item: &'a Item,
output: OnceLock<HashMap<Label, PileValue<'a>>>,
pub struct EpubMetaExtractor {
item: Item,
output: OnceLock<HashMap<Label, PileValue>>,
}
impl<'a> EpubMetaExtractor<'a> {
pub fn new(item: &'a Item) -> Self {
impl EpubMetaExtractor {
pub fn new(item: &Item) -> Self {
Self {
item,
item: item.clone(),
output: OnceLock::new(),
}
}
async fn get_inner(&self) -> Result<&HashMap<Label, PileValue<'a>>, std::io::Error> {
async fn get_inner(&self) -> Result<&HashMap<Label, PileValue>, std::io::Error> {
if let Some(x) = self.output.get() {
return Ok(x);
}
@@ -61,13 +64,13 @@ impl<'a> EpubMetaExtractor<'a> {
}
};
let mut output: HashMap<Label, PileValue<'a>> = HashMap::new();
let mut output: HashMap<Label, PileValue> = HashMap::new();
#[expect(clippy::unwrap_used)]
for (key, val) in raw_meta {
let label = Label::new(key).unwrap();
let value = match val {
Some(s) => PileValue::String(s.into()),
Some(s) => PileValue::String(Arc::new(s.into())),
None => PileValue::Null,
};
output.insert(label, value);
@@ -78,12 +81,9 @@ impl<'a> EpubMetaExtractor<'a> {
}
#[async_trait::async_trait]
impl ObjectExtractor for EpubMetaExtractor<'_> {
async fn field<'a>(
&'a self,
name: &Label,
) -> Result<Option<&'a PileValue<'a>>, std::io::Error> {
Ok(self.get_inner().await?.get(name))
impl ObjectExtractor for EpubMetaExtractor {
async fn field(&self, name: &Label) -> Result<Option<PileValue>, std::io::Error> {
Ok(self.get_inner().await?.get(name).cloned())
}
async fn fields(&self) -> Result<Vec<Label>, std::io::Error> {

View File

@@ -1,24 +1,27 @@
use epub::doc::EpubDoc;
use pile_config::Label;
use std::{collections::HashMap, sync::OnceLock};
use std::{
collections::HashMap,
sync::{Arc, OnceLock},
};
use tracing::debug;
use crate::{Item, PileValue, SyncReadBridge, extract::ObjectExtractor};
pub struct EpubTextExtractor<'a> {
item: &'a Item,
output: OnceLock<HashMap<Label, PileValue<'a>>>,
pub struct EpubTextExtractor {
item: Item,
output: OnceLock<HashMap<Label, PileValue>>,
}
impl<'a> EpubTextExtractor<'a> {
pub fn new(item: &'a Item) -> Self {
impl EpubTextExtractor {
pub fn new(item: &Item) -> Self {
Self {
item,
item: item.clone(),
output: OnceLock::new(),
}
}
async fn get_inner(&self) -> Result<&HashMap<Label, PileValue<'a>>, std::io::Error> {
async fn get_inner(&self) -> Result<&HashMap<Label, PileValue>, std::io::Error> {
if let Some(x) = self.output.get() {
return Ok(x);
}
@@ -61,7 +64,7 @@ impl<'a> EpubTextExtractor<'a> {
#[expect(clippy::unwrap_used)]
let output = HashMap::from([(
Label::new("text").unwrap(),
PileValue::String(raw_text.into()),
PileValue::String(Arc::new(raw_text.into())),
)]);
let _ = self.output.set(output);
@@ -88,12 +91,9 @@ fn strip_html(html: &str) -> String {
}
#[async_trait::async_trait]
impl ObjectExtractor for EpubTextExtractor<'_> {
async fn field<'a>(
&'a self,
name: &Label,
) -> Result<Option<&'a PileValue<'a>>, std::io::Error> {
Ok(self.get_inner().await?.get(name))
impl ObjectExtractor for EpubTextExtractor {
async fn field(&self, name: &Label) -> Result<Option<PileValue>, std::io::Error> {
Ok(self.get_inner().await?.get(name).cloned())
}
async fn fields(&self) -> Result<Vec<Label>, std::io::Error> {

View File

@@ -12,13 +12,13 @@ use crate::{
extract::{MapExtractor, ObjectExtractor},
};
pub struct EpubExtractor<'a> {
inner: MapExtractor<'a>,
pub struct EpubExtractor {
inner: MapExtractor,
}
impl<'a> EpubExtractor<'a> {
impl EpubExtractor {
#[expect(clippy::unwrap_used)]
pub fn new(item: &'a Item) -> Self {
pub fn new(item: &Item) -> Self {
let inner = MapExtractor {
inner: HashMap::from([
(
@@ -37,19 +37,8 @@ impl<'a> EpubExtractor<'a> {
}
#[async_trait::async_trait]
impl ObjectExtractor for EpubExtractor<'_> {
async fn field<'a>(
&'a self,
name: &pile_config::Label,
) -> Result<Option<&'a PileValue<'a>>, std::io::Error> {
#[expect(clippy::unwrap_used)]
if name.as_str() == "text" {
match self.inner.inner.get(name).unwrap() {
PileValue::ObjectExtractor(x) => return x.field(name).await,
_ => unreachable!(),
};
}
impl ObjectExtractor for EpubExtractor {
async fn field(&self, name: &pile_config::Label) -> Result<Option<PileValue>, std::io::Error> {
self.inner.field(name).await
}