Skip to content

Commit c611a6f

Browse files
committed
Simplify types
This patch removes a number of unnecessary `Send` and `Sync` constraints, and consolidates implementations of RepositoryProvider and RepositoryStorage.
1 parent fdc11e6 commit c611a6f

File tree

11 files changed

+121
-291
lines changed

11 files changed

+121
-291
lines changed

interop-tests/tests/test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn rust_tuf_identity_consistent_snapshot_true() {
105105

106106
fn test_key_rotation<D>(dir: PathBuf)
107107
where
108-
D: DataInterchange + Sync,
108+
D: DataInterchange,
109109
{
110110
block_on(async {
111111
let mut suite = TestKeyRotation::<D>::new(dir);
@@ -116,7 +116,7 @@ where
116116
/// TestKeyRotation is the main driver for running the key rotation tests.
117117
struct TestKeyRotation<D>
118118
where
119-
D: DataInterchange + Sync,
119+
D: DataInterchange,
120120
{
121121
/// The paths to each test step directory.
122122
test_steps: Vec<PathBuf>,
@@ -131,7 +131,7 @@ where
131131

132132
impl<D> TestKeyRotation<D>
133133
where
134-
D: DataInterchange + Sync,
134+
D: DataInterchange,
135135
{
136136
fn new(test_dir: PathBuf) -> Self {
137137
let mut test_steps = Vec::new();
@@ -207,7 +207,7 @@ where
207207
/// Extract the initial key ids from the first step.
208208
async fn extract_keys<D>(dir: &Path) -> Vec<PublicKey>
209209
where
210-
D: DataInterchange + Sync,
210+
D: DataInterchange,
211211
{
212212
let remote = init_remote::<D>(dir);
213213

@@ -230,7 +230,7 @@ where
230230

231231
fn init_remote<D>(dir: &Path) -> FileSystemRepository<D>
232232
where
233-
D: DataInterchange + Sync,
233+
D: DataInterchange,
234234
{
235235
FileSystemRepositoryBuilder::new(dir)
236236
.metadata_prefix(Path::new("repository"))

tuf/src/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use crate::verify::Verified;
6868
#[derive(Debug)]
6969
pub struct Client<D, L, R>
7070
where
71-
D: DataInterchange + Sync,
71+
D: DataInterchange,
7272
L: RepositoryProvider<D> + RepositoryStorage<D>,
7373
R: RepositoryProvider<D>,
7474
{
@@ -80,7 +80,7 @@ where
8080

8181
impl<D, L, R> Client<D, L, R>
8282
where
83-
D: DataInterchange + Sync,
83+
D: DataInterchange,
8484
L: RepositoryProvider<D> + RepositoryStorage<D>,
8585
R: RepositoryProvider<D>,
8686
{
@@ -1127,7 +1127,7 @@ where
11271127
#[derive(Debug)]
11281128
pub struct Parts<D, L, R>
11291129
where
1130-
D: DataInterchange + Sync,
1130+
D: DataInterchange,
11311131
L: RepositoryProvider<D> + RepositoryStorage<D>,
11321132
R: RepositoryProvider<D>,
11331133
{
@@ -1156,7 +1156,7 @@ async fn fetch_metadata_from_local_or_else_remote<'a, D, L, R, M>(
11561156
remote: &'a Repository<R, D>,
11571157
) -> Result<(bool, RawSignedMetadata<D, M>)>
11581158
where
1159-
D: DataInterchange + Sync,
1159+
D: DataInterchange,
11601160
L: RepositoryProvider<D> + RepositoryStorage<D>,
11611161
R: RepositoryProvider<D>,
11621162
M: Metadata + 'static,

tuf/src/database.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use crate::verify::{self, Verified};
1717
use crate::Result;
1818

1919
/// Contains trusted TUF metadata and can be used to verify other metadata and targets.
20-
#[derive(Clone, Debug)]
20+
#[derive(Debug)]
2121
pub struct Database<D: DataInterchange> {
2222
trusted_root: Verified<RootMetadata>,
23-
trusted_snapshot: Option<Verified<SnapshotMetadata>>,
2423
trusted_targets: Option<Verified<TargetsMetadata>>,
24+
trusted_snapshot: Option<Verified<SnapshotMetadata>>,
2525
trusted_timestamp: Option<Verified<TimestampMetadata>>,
2626
trusted_delegations: HashMap<MetadataPath, Verified<TargetsMetadata>>,
2727
interchange: PhantomData<D>,
@@ -1041,6 +1041,19 @@ impl<D: DataInterchange> Database<D> {
10411041
}
10421042
}
10431043

1044+
impl<D: DataInterchange> Clone for Database<D> {
1045+
fn clone(&self) -> Self {
1046+
Self {
1047+
trusted_root: self.trusted_root.clone(),
1048+
trusted_targets: self.trusted_targets.clone(),
1049+
trusted_snapshot: self.trusted_snapshot.clone(),
1050+
trusted_timestamp: self.trusted_timestamp.clone(),
1051+
trusted_delegations: self.trusted_delegations.clone(),
1052+
interchange: PhantomData,
1053+
}
1054+
}
1055+
}
1056+
10441057
#[cfg(test)]
10451058
mod test {
10461059
use super::*;

tuf/src/interchange/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ pub use cjson::{Json, JsonPretty};
55

66
use serde::de::DeserializeOwned;
77
use serde::ser::Serialize;
8-
use std::fmt::Debug;
98

109
use crate::Result;
1110

1211
/// The format used for data interchange, serialization, and deserialization.
13-
pub trait DataInterchange: Debug + PartialEq + Clone {
12+
pub trait DataInterchange: Sync {
1413
/// The type of data that is contained in the `signed` portion of metadata.
15-
type RawData: Serialize + DeserializeOwned + Clone + PartialEq;
14+
type RawData: Serialize + DeserializeOwned + PartialEq;
1615

1716
/// The data interchange's extension.
1817
fn extension() -> &'static str;

tuf/src/repo_builder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct Staged<D: DataInterchange, M: Metadata> {
205205

206206
struct RepoContext<'a, D, R>
207207
where
208-
D: DataInterchange + Sync,
208+
D: DataInterchange,
209209
R: RepositoryStorage<D>,
210210
{
211211
repo: R,
@@ -228,7 +228,7 @@ where
228228

229229
impl<'a, D, R> RepoContext<'a, D, R>
230230
where
231-
D: DataInterchange + Sync,
231+
D: DataInterchange,
232232
R: RepositoryStorage<D>,
233233
{
234234
fn root_keys_changed(&self, root: &Verified<RootMetadata>) -> bool {
@@ -309,7 +309,7 @@ where
309309
/// This helper builder simplifies the process of creating new metadata.
310310
pub struct RepoBuilder<'a, D, R, S = Root>
311311
where
312-
D: DataInterchange + Sync,
312+
D: DataInterchange,
313313
R: RepositoryStorage<D>,
314314
S: State,
315315
{
@@ -319,7 +319,7 @@ where
319319

320320
impl<'a, D, R> RepoBuilder<'a, D, R, Root>
321321
where
322-
D: DataInterchange + Sync,
322+
D: DataInterchange,
323323
R: RepositoryStorage<D>,
324324
{
325325
/// Create a [RepoBuilder] for creating metadata for a new repository.
@@ -762,7 +762,7 @@ where
762762

763763
impl<'a, D, R> RepoBuilder<'a, D, R, Targets<D>>
764764
where
765-
D: DataInterchange + Sync,
765+
D: DataInterchange,
766766
R: RepositoryStorage<D>,
767767
{
768768
/// Whether or not to include the length of the targets, and any delegated targets, in the
@@ -1022,7 +1022,7 @@ where
10221022

10231023
impl<'a, D, R> RepoBuilder<'a, D, R, Snapshot<D>>
10241024
where
1025-
D: DataInterchange + Sync,
1025+
D: DataInterchange,
10261026
R: RepositoryStorage<D>,
10271027
{
10281028
/// Whether or not to include the length of the targets, and any delegated targets, in the
@@ -1180,7 +1180,7 @@ where
11801180

11811181
impl<'a, D, R> RepoBuilder<'a, D, R, Timestamp<D>>
11821182
where
1183-
D: DataInterchange + Sync,
1183+
D: DataInterchange,
11841184
R: RepositoryStorage<D>,
11851185
{
11861186
/// Whether or not to include the length of the snapshot, and any delegated snapshot, in the
@@ -1338,7 +1338,7 @@ where
13381338

13391339
impl<'a, D, R> RepoBuilder<'a, D, R, Done<D>>
13401340
where
1341-
D: DataInterchange + Sync,
1341+
D: DataInterchange,
13421342
R: RepositoryStorage<D>,
13431343
{
13441344
/// Commit the metadata for this repository, then write all metadata to the repository. Before

0 commit comments

Comments
 (0)