pub struct Learner {
pub config: Config,
pub database: Database,
pub retriever: Retriever,
}
Expand description
Main entry point for the library.
Coordinates database access, paper retrieval, and configuration management. Use the builder pattern to create configured instances.
§Examples
// Create with defaults
let learner = Learner::new().await?;
// Or use the builder for more control
let learner = Learner::builder().with_path("config/").build().await?;
Fields§
§config: Config
Active configuration
database: Database
Database connection and operations
retriever: Retriever
Paper retrieval system
Implementations§
Source§impl Learner
impl Learner
Sourcepub fn builder() -> LearnerBuilder
pub fn builder() -> LearnerBuilder
Returns a builder for creating a new configured Learner instance.
This is the recommended way to construct a Learner as it provides fine-grained control over initialization options.
§Examples
let learner = Learner::builder().with_path("~/.learner").build().await?;
Sourcepub async fn new() -> Result<Self>
pub async fn new() -> Result<Self>
Creates a new Learner instance with default configuration.
This will:
- Load or create configuration at default location
- Initialize database in default location
- Set up default paper storage
- Configure default retrievers
§Errors
Returns error if:
- Configuration loading fails
- Directory creation fails
- Database initialization fails
§Examples
let mut learner = Learner::new().await?;
// Ready to use with default configuration
let paper = learner.retriever.get_paper("2301.07041").await?;
Sourcepub async fn from_path(path: impl AsRef<Path>) -> Result<Self>
pub async fn from_path(path: impl AsRef<Path>) -> Result<Self>
Creates a new Learner instance from a configuration file path.
Loads configuration from the specified directory, which should contain a config.toml file.
§Arguments
path
- Directory containing config.toml
§Errors
Returns error if:
- Configuration file does not exist
- TOML parsing fails
- Directory creation fails
- Initialization fails
§Examples
// Load from custom location
let learner = Learner::from_path("~/research/papers/config").await?;
// Or use environment-specific config
let learner = Learner::from_path("/etc/learner").await?;
Sourcepub async fn with_config(config: Config) -> Result<Self>
pub async fn with_config(config: Config) -> Result<Self>
Creates a new Learner instance with explicit configuration.
Use this when you need complete control over the configuration or are generating configuration programmatically.
§Arguments
config
- Complete configuration to use
§Errors
Returns error if:
- Directory creation fails
- Database initialization fails
- Retriever configuration fails
§Examples
// Create custom configuration
let config = Config::default()
.with_database_path(&PathBuf::from("papers.db"))
.with_storage_path(&PathBuf::from("papers"));
// Initialize with custom config
let learner = Learner::with_config(config).await?;
Sourcepub async fn init() -> Result<Self>
pub async fn init() -> Result<Self>
Initializes a new Learner instance with example configuration.
This method:
- Creates example configuration
- Writes example retriever configs (arXiv, DOI)
- Sets up directory structure
- Initializes empty database
Ideal for first-time setup or testing.
§Errors
Returns error if:
- Configuration initialization fails
- Directory creation fails
- Example config writing fails
- Database initialization fails
§Examples
// Initialize new installation with examples
let mut learner = Learner::init().await?;
// Ready to use with example retrievers
let paper = learner.retriever.get_paper("2301.07041").await?;
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Learner
impl RefUnwindSafe for Learner
impl Send for Learner
impl Sync for Learner
impl Unpin for Learner
impl UnwindSafe for Learner
Blanket Implementations§
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,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more