pub struct Engine { /* private fields */ }Expand description
书源运行时引擎。
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new(source: BookSource) -> Result<Self>
pub fn new(source: BookSource) -> Result<Self>
用默认 reqwest 取页后端构建。
Sourcepub fn with_fetcher(source: BookSource, fetcher: Arc<dyn Fetcher>) -> Self
pub fn with_fetcher(source: BookSource, fetcher: Arc<dyn Fetcher>) -> Self
注入自定义取页后端(测试替身 / 反爬适配器)构建。
这是唯一真实构造器:共享字段(登录态/cookie 库/作用域变量)的默认初始化只在此处,
其余构造器(Engine::new / with_browser_assist)一律委托,避免新增字段漏改。
Sourcepub fn with_login_header(self, login_header: BTreeMap<String, String>) -> Self
pub fn with_login_header(self, login_header: BTreeMap<String, String>) -> Self
注入登录态请求头(登录后由调用方从 per-source 状态取出)。链式构造:
Engine::new(src)?.with_login_header(state.login_header)。空 map 等同未登录。
用持久化 cookie(注册域 -> "k=v",来自 per-source 状态)初始化 cookie 库。链式构造。
导出当前 cookie 库中的 persistent cookie(注册域 -> "k=v"),供调用方落盘。
session cookie 不导出(重启失效)。
Sourcepub fn with_book_vars(self, book_vars: BTreeMap<String, String>) -> Self
pub fn with_book_vars(self, book_vars: BTreeMap<String, String>) -> Self
注入书籍级捕获变量(scope=book,来自 per-book 快照)。链式构造(贴 Engine::with_login_header)。
Sourcepub fn with_source_vars(self, source_vars: &BTreeMap<String, String>) -> Self
pub fn with_source_vars(self, source_vars: &BTreeMap<String, String>) -> Self
合并书源级捕获变量(scope=source,来自 per-source 状态)。链式构造。
Sourcepub fn book_vars(&self) -> BTreeMap<String, String>
pub fn book_vars(&self) -> BTreeMap<String, String>
导出书籍级捕获变量,供 app 随 per-book 快照落盘(scope=book 跨会话复用的承载)。
Sourcepub fn source_vars(&self) -> BTreeMap<String, String>
pub fn source_vars(&self) -> BTreeMap<String, String>
导出书源级捕获变量,供 app 落盘(可选;默认构建为进程内)。
Sourcepub fn source(&self) -> &BookSource
pub fn source(&self) -> &BookSource
暴露只读配置。
Sourcepub fn source_url(&self) -> &str
pub fn source_url(&self) -> &str
书源 URL(per-source 登录态文件的 key,供 app 回写 persistent cookie 落盘时定位)。
Sourcepub async fn warmup(&self)
pub async fn warmup(&self)
预热:按 http.warmup 先访问若干页以累积会话 cookie(失败忽略)。
走 Engine::run_request 统一管线——enabledCookieJar 时预热页的 Set-Cookie
才会回灌引擎 cookie 库(loginCheckJs 在预热页可能误判,但错误被吞,不影响预热语义)。
Sourcepub async fn search(
&self,
key: &str,
page: u32,
page_size: u32,
) -> Result<BookList>
pub async fn search( &self, key: &str, page: u32, page_size: u32, ) -> Result<BookList>
搜索。返回书列表 + 可选精确总页数(render-dual-source)/ 边界(list-has-more)。
key 作为 {{key}} 变量并入共享列表页 runner。
Sourcepub async fn explore(
&self,
entry: &ExploreEntry,
page: u32,
page_size: u32,
) -> Result<BookList>
pub async fn explore( &self, entry: &ExploreEntry, page: u32, page_size: u32, ) -> Result<BookList>
浏览选中入口的某一页(由用户递增 page 单页取)。用入口变量驱动共享列表页 runner;
取页 URL 由 explore.page.request 用入口变量 + {{page}} 模板生成(入口不再持固定 URL)。
Sourcepub async fn explore_entries(&self) -> Result<Vec<ExploreEntry>>
pub async fn explore_entries(&self) -> Result<Vec<ExploreEntry>>
加载 explore 入口(dynamic-explore-entries):按声明顺序遍历入口源数组,合并各源产出的
扁平 ExploreEntry(静态固定入口 + 远端抓取动态入口)。
失败策略:某个(动态)源失败时保留已成功入口(含前面的静态源),不阻断;仅当零入口产出 且有源报错时返回该错误。完全成功(无任何源报错)才写入口缓存,使下次进入可重试失败的动态源。
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Engine
impl !UnwindSafe for Engine
impl Freeze for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl UnsafeUnpin for Engine
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.