Backends

Enum Backends 

Source
pub enum Backends {
    Dumb,
    RoyalRoad(RoyalRoad),
    LibRead(LibRead),
    FreeWebNovel(FreeWebNovel),
    LightNovelWorld(LightNovelWorld),
}
Expand description

Enum listing all available backends. A new backend may be constructed using Backends::new.

Variants§

§

Dumb

A dumb backend that should never be constructed, but is necessary for iteration (with strum::EnumIter & other features.

§

RoyalRoad(RoyalRoad)

A RoyalRoad backend

§

LibRead(LibRead)

A LibRead backend

§

FreeWebNovel(FreeWebNovel)

A FreeWebNovel backend

§

LightNovelWorld(LightNovelWorld)

A LightNovelWorld backend

Implementations§

Source§

impl Backends

Source

pub fn get_ordering_function( &self, ) -> Box<dyn Fn(&Chapter, &Chapter) -> Ordering>

Returns the ordering function specific to the underlying backend.

§Panics

Panics when self is Backends::Dumb.

Source

pub fn get_backend_regexps(&self) -> Vec<Regex>

Returns the regexps used by the underlying backend. Backends::Dumb returns an empty Vec.

Source

pub fn get_backend_name(&self) -> &'static str

Returns the underlying backend name.

Trait Implementations§

Source§

impl Backend for Backends

All possible backend variants are contained within Backends. This implementation tries to dispatch method calls to their appropriate implementors.

use libwebnovel::{Backend, Backends};
let backend =
    Backends::new("https://www.royalroad.com/fiction/21220/mother-of-learning").unwrap();
assert_eq!(backend.title().unwrap(), "Mother of Learning");
Source§

fn get_backend_regexps() -> Vec<Regex>

Not implemented for Backends. Use Backends::get_backend_regexps(&self) instead.

Source§

fn get_backend_name() -> &'static str

Not implemented for Backends. Use Backends::get_backend_name(&self) instead.

Source§

fn get_ordering_function() -> Box<dyn Fn(&Chapter, &Chapter) -> Ordering>

Can’t implement this function for backends without reference to self. use Backends::get_ordering_function(&self) instead.

Source§

fn new(url: &str) -> Result<Self, BackendError>

Builds a new backend for a given URL. Auto-detects the backend to use from the given URL, returning BackendError::NoMatchingBackendFound if none could be found.

use libwebnovel::{Backend, Backends};
let backend =
    Backends::new("https://www.royalroad.com/fiction/21220/mother-of-learning").unwrap();
assert_eq!(backend.title().unwrap(), "Mother of Learning");
Source§

fn title(&self) -> Result<String, BackendError>

Returns the title of the webnovel. See Backends::new for an example.

Source§

fn url(&self) -> String

Returns the URL of the webnovel.

use libwebnovel::{Backend, Backends};
let backend =
    Backends::new("https://www.royalroad.com/fiction/21220/mother-of-learning").unwrap();
assert_eq!(
    backend.url(),
    "https://www.royalroad.com/fiction/21220/mother-of-learning"
);
Source§

fn get_authors(&self) -> Result<Vec<String>, BackendError>

Returns the author(s) of the webnovel

use libwebnovel::{Backend, Backends};
let backend =
    Backends::new("https://www.royalroad.com/fiction/21220/mother-of-learning").unwrap();
assert_eq!(
    backend.get_authors().unwrap(),
    vec!["nobody103".to_string()]
);
Source§

fn get_chapter(&self, chapter_number: usize) -> Result<Chapter, BackendError>

Returns a chapter of the webnovel, given its chapter number

use libwebnovel::{Backend, Backends};
let backend =
    Backends::new("https://www.royalroad.com/fiction/21220/mother-of-learning").unwrap();
let chapter = backend.get_chapter(1).unwrap();
assert_eq!(
    chapter.title(),
    &Some("1. Good Morning Brother".to_string())
);
assert_eq!(*chapter.index(), 1);
Source§

fn get_chapter_count(&self) -> Result<usize, BackendError>

Returns the total count of the webnovel’s chapters.

§Example
use libwebnovel::{Backend, Backends};
let backend =
    Backends::new("https://www.royalroad.com/fiction/21220/mother-of-learning").unwrap();
assert_eq!(backend.get_chapter_count().unwrap(), 109);
§Panics

Panics when used on the Backends::Dumb backend.

Source§

fn immutable_identifier(&self) -> Result<String, BackendError>

Returns something that can be used to identify this novel, and won’t change if (for instance) the title changes.
Source§

fn cover_url(&self) -> Result<String, BackendError>

Returns the fictions’ cover URL, if any
Source§

fn get_chapter_list(&self) -> Result<Vec<(usize, String)>, BackendError>

Returns a vector of available chapters without requesting the chapters themselves. The goal is to be able to detect collisions between something stored locally and a distant source. Read more
Source§

fn get_chapters(&self) -> Result<Vec<Chapter>, BackendError>

Returns all chapters for this fiction. The default implementation simply calls Self::get_chapter repeatedly
Source§

fn cover(&self) -> Result<Vec<u8>, BackendError>

Returns the fictions’ cover as a byte array, if any.
Source§

impl Debug for Backends

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Backends

Source§

fn default() -> Backends

Returns the “default value” for a type. Read more
Source§

impl EnumCount for Backends

Source§

const COUNT: usize = 5usize

Source§

impl IntoEnumIterator for Backends

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more