Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Arti
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jill
Arti
Commits
6da5c9af
Commit
6da5c9af
authored
2 years ago
by
Ian Jackson
Browse files
Options
Downloads
Patches
Plain Diff
arti: ArtiConfig: derive ArtiConfigBuilder
Replace handwritten builder struct, accessors, and builder function.
parent
79decd4a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
crates/arti/src/cfg.rs
+13
-87
13 additions, 87 deletions
crates/arti/src/cfg.rs
with
13 additions
and
87 deletions
crates/arti/src/cfg.rs
+
13
−
87
View file @
6da5c9af
...
...
@@ -114,21 +114,33 @@ impl SystemConfig {
///
/// NOTE: These are NOT the final options or their final layout. Expect NO
/// stability here.
#[derive(Debug,
Clone,
Eq,
PartialEq,
Default)]
#[derive(Debug,
Builder,
Clone,
Eq,
PartialEq,
Default)]
#[builder(derive(Deserialize))]
#[builder(build_fn(error
=
"ConfigBuildError"
))]
pub
struct
ArtiConfig
{
/// Configuration for application behavior.
#[builder(sub_builder)]
#[builder_field_attr(serde(default))]
application
:
ApplicationConfig
,
/// Configuration for proxy listeners
#[builder(sub_builder)]
#[builder_field_attr(serde(default))]
proxy
:
ProxyConfig
,
/// Logging configuration
#[builder(sub_builder)]
#[builder_field_attr(serde(default))]
logging
:
LoggingConfig
,
/// Information on system resources used by Arti.
#[builder(sub_builder)]
#[builder_field_attr(serde(default))]
pub
(
crate
)
system
:
SystemConfig
,
/// Configuration of the actual Tor client
#[builder(sub_builder)]
#[builder_field_attr(serde(flatten))]
tor
:
TorClientConfig
,
}
...
...
@@ -176,92 +188,6 @@ impl ArtiConfig {
}
}
/// Builder object used to construct an ArtiConfig.
///
/// Most code won't need this, and should use [`TorClientConfigBuilder`] instead.
///
/// Unlike other builder types in Arti, this builder works by exposing an
/// inner builder for each section in the [`TorClientConfig`].
#[derive(Default,
Clone,
Deserialize)]
// This ought to be replaced by a derive-builder generated struct (probably as part of #374),
// but currently derive-builder can't do this.
pub
struct
ArtiConfigBuilder
{
/// Builder for the actual Tor client.
#[serde(flatten)]
tor
:
TorClientConfigBuilder
,
/// Builder for the application section
#[serde(default)]
application
:
ApplicationConfigBuilder
,
/// Builder for the proxy section.
#[serde(default)]
proxy
:
ProxyConfigBuilder
,
/// Builder for the logging section.
#[serde(default)]
logging
:
LoggingConfigBuilder
,
/// Builder for system resource configuration.
#[serde(default)]
system
:
SystemConfigBuilder
,
}
impl
ArtiConfigBuilder
{
/// Try to construct a new [`ArtiConfig`] from this builder.
pub
fn
build
(
&
self
)
->
Result
<
ArtiConfig
,
ConfigBuildError
>
{
let
application
=
self
.application
.build
()
.map_err
(|
e
|
e
.within
(
"application"
))
?
;
let
proxy
=
self
.proxy
.build
()
.map_err
(|
e
|
e
.within
(
"proxy"
))
?
;
let
logging
=
self
.logging
.build
()
.map_err
(|
e
|
e
.within
(
"logging"
))
?
;
let
system
=
self
.system
.build
()
.map_err
(|
e
|
e
.within
(
"system"
))
?
;
let
tor
=
TorClientConfigBuilder
::
from
(
self
.clone
());
let
tor
=
tor
.build
()
?
;
Ok
(
ArtiConfig
{
application
,
proxy
,
logging
,
system
,
tor
,
})
}
/// Return a mutable reference to an [`ApplicationConfigBuilder`] to use in
/// configuring the Arti process.
pub
fn
application
(
&
mut
self
)
->
&
mut
ApplicationConfigBuilder
{
&
mut
self
.application
}
/// Return a mutable reference to a [`ProxyConfig`] to use in
/// configuring the Arti process.
pub
fn
proxy
(
&
mut
self
)
->
&
mut
ProxyConfigBuilder
{
&
mut
self
.proxy
}
/// Return a mutable reference to a
/// [`LoggingConfigBuilder`]
/// to use in configuring the Arti process.
pub
fn
logging
(
&
mut
self
)
->
&
mut
LoggingConfigBuilder
{
&
mut
self
.logging
}
/// Return a mutable reference to a `TorClientConfigBuilder`.
/// to use in configuring the underlying Tor network.
///
/// Most programs shouldn't need to alter this configuration: it's only for
/// cases when you need to use a nonstandard set of Tor directory authorities
/// and fallback caches.
pub
fn
tor
(
&
mut
self
)
->
&
mut
TorClientConfigBuilder
{
&
mut
self
.tor
}
/// Return a mutable reference to a [`SystemConfigBuilder`].
///
/// This section controls the system parameters used by Arti.
pub
fn
system
(
&
mut
self
)
->
&
mut
SystemConfigBuilder
{
&
mut
self
.system
}
}
#[cfg(test)]
mod
test
{
#![allow(clippy::unwrap_used)]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment