pub struct ContextBuilder {
dbfile: PathBuf,
id: u32,
events: Events,
stock_strings: StockStrings,
password: Option<String>,
push_subscriber: Option<PushSubscriber>,
}
Expand description
Builder for the Context
.
Many arguments to the Context
are kind of optional and only needed to handle
multiple contexts, for which the account manager should be
used. This builder makes creating a new context simpler, especially for the
standalone-context case.
§Examples
Creating a new unencrypted database:
use deltachat::context::ContextBuilder;
let dir = tempfile::tempdir().unwrap();
let context = ContextBuilder::new(dir.path().join("db"))
.open()
.await
.unwrap();
drop(context);
To use an encrypted database provide a password. If the database does not yet exist it will be created:
use deltachat::context::ContextBuilder;
let dir = tempfile::tempdir().unwrap();
let context = ContextBuilder::new(dir.path().join("db"))
.with_password("secret".into())
.open()
.await
.unwrap();
drop(context);
Fields§
§dbfile: PathBuf
§id: u32
§events: Events
§stock_strings: StockStrings
§password: Option<String>
§push_subscriber: Option<PushSubscriber>
Implementations§
Source§impl ContextBuilder
impl ContextBuilder
Sourcepub fn new(dbfile: PathBuf) -> Self
pub fn new(dbfile: PathBuf) -> Self
Create the builder using the given database file.
The dbfile should be in a dedicated directory and this directory must exist. The
Context
will create other files and folders in the same directory as the
database file used.
Sourcepub fn with_id(self, id: u32) -> Self
pub fn with_id(self, id: u32) -> Self
Sets the context ID.
This identifier is used e.g. in Event
s to identify which Context
an event
belongs to. The only real limit on it is that it should not conflict with any other
Context
s you currently have open. So if you handle multiple Context
s you
may want to use this.
Note that the account manager is designed to handle the
common case for using multiple Context
instances.
Sourcepub fn with_events(self, events: Events) -> Self
pub fn with_events(self, events: Events) -> Self
Sets the event channel for this Context
.
Mostly useful when using multiple Context
s, this allows creating one Events
channel and passing it to all Context
s so all events are received on the same
channel.
Note that the account manager is designed to handle the
common case for using multiple Context
instances.
Sourcepub fn with_stock_strings(self, stock_strings: StockStrings) -> Self
pub fn with_stock_strings(self, stock_strings: StockStrings) -> Self
Sets the StockStrings
map to use for this Context
.
This is useful in order to share the same translation strings in all Context
s.
The mapping may be empty when set, it will be populated by
[Context::set_stock-translation
] or Accounts::set_stock_translation
calls.
Note that the account manager is designed to handle the
common case for using multiple Context
instances.
Sourcepub fn with_password(self, password: String) -> Self
pub fn with_password(self, password: String) -> Self
Sets the password to unlock the database.
If an encrypted database is used it must be opened with a password. Setting a password on a new database will enable encryption.
Sourcepub(crate) fn with_push_subscriber(
self,
push_subscriber: PushSubscriber,
) -> Self
pub(crate) fn with_push_subscriber( self, push_subscriber: PushSubscriber, ) -> Self
Sets push subscriber.
Trait Implementations§
Source§impl Clone for ContextBuilder
impl Clone for ContextBuilder
Source§fn clone(&self) -> ContextBuilder
fn clone(&self) -> ContextBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more