mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-02 11:13:29 +00:00
Stronger lint on sync subcrate
This commit is contained in:
parent
aa9a117a22
commit
cee3389eb7
|
@ -30,7 +30,7 @@ pub const HEIF_EXTENSIONS: [&str; 8] = [
|
||||||
/// This is the target pixel count for all SVG images to be rendered at.
|
/// This is the target pixel count for all SVG images to be rendered at.
|
||||||
///
|
///
|
||||||
/// It is 512x512, but if the SVG has a non-1:1 aspect ratio we need to account for that.
|
/// It is 512x512, but if the SVG has a non-1:1 aspect ratio we need to account for that.
|
||||||
pub const SVG_TARGET_PX: f32 = 262_144_f32;
|
pub const SVG_TARGET_PX: f32 = 262_144f32;
|
||||||
|
|
||||||
/// The size that PDF pages are rendered at.
|
/// The size that PDF pages are rendered at.
|
||||||
///
|
///
|
||||||
|
|
|
@ -10,14 +10,21 @@
|
||||||
clippy::unwrap_used,
|
clippy::unwrap_used,
|
||||||
unused_qualifications,
|
unused_qualifications,
|
||||||
rust_2018_idioms,
|
rust_2018_idioms,
|
||||||
clippy::expect_used,
|
|
||||||
trivial_casts,
|
trivial_casts,
|
||||||
trivial_numeric_casts,
|
trivial_numeric_casts,
|
||||||
unused_allocation,
|
unused_allocation,
|
||||||
clippy::as_conversions,
|
clippy::unnecessary_cast,
|
||||||
clippy::dbg_macro
|
clippy::cast_lossless,
|
||||||
|
clippy::cast_possible_truncation,
|
||||||
|
clippy::cast_possible_wrap,
|
||||||
|
clippy::cast_precision_loss,
|
||||||
|
clippy::cast_sign_loss,
|
||||||
|
clippy::dbg_macro,
|
||||||
|
clippy::deprecated_cfg_attr,
|
||||||
|
clippy::separated_literal_suffix,
|
||||||
|
deprecated
|
||||||
)]
|
)]
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(deprecated_in_future)]
|
||||||
#![allow(clippy::missing_errors_doc, clippy::module_name_repetitions)]
|
#![allow(clippy::missing_errors_doc, clippy::module_name_repetitions)]
|
||||||
|
|
||||||
use std::{fs, path::Path};
|
use std::{fs, path::Path};
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uhlc::NTP64;
|
use uhlc::NTP64;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -6,11 +8,12 @@ use crate::{CRDTOperation, CRDTOperationData};
|
||||||
|
|
||||||
pub type CompressedCRDTOperationsForModel = Vec<(rmpv::Value, Vec<CompressedCRDTOperation>)>;
|
pub type CompressedCRDTOperationsForModel = Vec<(rmpv::Value, Vec<CompressedCRDTOperation>)>;
|
||||||
|
|
||||||
/// Stores a bunch of CRDTOperations in a more memory-efficient form for sending to the cloud.
|
/// Stores a bunch of [`CRDTOperation`]s in a more memory-efficient form for sending to the cloud.
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
pub struct CompressedCRDTOperations(pub Vec<(Uuid, Vec<(u16, CompressedCRDTOperationsForModel)>)>);
|
pub struct CompressedCRDTOperations(pub Vec<(Uuid, Vec<(u16, CompressedCRDTOperationsForModel)>)>);
|
||||||
|
|
||||||
impl CompressedCRDTOperations {
|
impl CompressedCRDTOperations {
|
||||||
|
#[must_use]
|
||||||
pub fn new(ops: Vec<CRDTOperation>) -> Self {
|
pub fn new(ops: Vec<CRDTOperation>) -> Self {
|
||||||
let mut compressed = vec![];
|
let mut compressed = vec![];
|
||||||
|
|
||||||
|
@ -32,34 +35,34 @@ impl CompressedCRDTOperations {
|
||||||
for op in ops_iter {
|
for op in ops_iter {
|
||||||
if instance_id != op.instance {
|
if instance_id != op.instance {
|
||||||
model.push((
|
model.push((
|
||||||
std::mem::replace(&mut record_id, op.record_id.clone()),
|
mem::replace(&mut record_id, op.record_id.clone()),
|
||||||
std::mem::take(&mut record),
|
mem::take(&mut record),
|
||||||
));
|
));
|
||||||
instance.push((
|
instance.push((
|
||||||
std::mem::replace(&mut model_str, op.model),
|
mem::replace(&mut model_str, op.model),
|
||||||
std::mem::take(&mut model),
|
mem::take(&mut model),
|
||||||
));
|
));
|
||||||
compressed.push((
|
compressed.push((
|
||||||
std::mem::replace(&mut instance_id, op.instance),
|
mem::replace(&mut instance_id, op.instance),
|
||||||
std::mem::take(&mut instance),
|
mem::take(&mut instance),
|
||||||
));
|
));
|
||||||
} else if model_str != op.model {
|
} else if model_str != op.model {
|
||||||
model.push((
|
model.push((
|
||||||
std::mem::replace(&mut record_id, op.record_id.clone()),
|
mem::replace(&mut record_id, op.record_id.clone()),
|
||||||
std::mem::take(&mut record),
|
mem::take(&mut record),
|
||||||
));
|
));
|
||||||
instance.push((
|
instance.push((
|
||||||
std::mem::replace(&mut model_str, op.model),
|
mem::replace(&mut model_str, op.model),
|
||||||
std::mem::take(&mut model),
|
mem::take(&mut model),
|
||||||
));
|
));
|
||||||
} else if record_id != op.record_id {
|
} else if record_id != op.record_id {
|
||||||
model.push((
|
model.push((
|
||||||
std::mem::replace(&mut record_id, op.record_id.clone()),
|
mem::replace(&mut record_id, op.record_id.clone()),
|
||||||
std::mem::take(&mut record),
|
mem::take(&mut record),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
record.push(CompressedCRDTOperation::from(op))
|
record.push(CompressedCRDTOperation::from(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
model.push((record_id, record));
|
model.push((record_id, record));
|
||||||
|
@ -69,6 +72,7 @@ impl CompressedCRDTOperations {
|
||||||
Self(compressed)
|
Self(compressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn first(&self) -> Option<(Uuid, u16, &rmpv::Value, &CompressedCRDTOperation)> {
|
pub fn first(&self) -> Option<(Uuid, u16, &rmpv::Value, &CompressedCRDTOperation)> {
|
||||||
self.0.first().and_then(|(instance, data)| {
|
self.0.first().and_then(|(instance, data)| {
|
||||||
data.first().and_then(|(model, data)| {
|
data.first().and_then(|(model, data)| {
|
||||||
|
@ -78,6 +82,7 @@ impl CompressedCRDTOperations {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn last(&self) -> Option<(Uuid, u16, &rmpv::Value, &CompressedCRDTOperation)> {
|
pub fn last(&self) -> Option<(Uuid, u16, &rmpv::Value, &CompressedCRDTOperation)> {
|
||||||
self.0.last().and_then(|(instance, data)| {
|
self.0.last().and_then(|(instance, data)| {
|
||||||
data.last().and_then(|(model, data)| {
|
data.last().and_then(|(model, data)| {
|
||||||
|
@ -104,6 +109,7 @@ impl CompressedCRDTOperations {
|
||||||
self.len() == 0
|
self.len() == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn into_ops(self) -> Vec<CRDTOperation> {
|
pub fn into_ops(self) -> Vec<CRDTOperation> {
|
||||||
let mut ops = vec![];
|
let mut ops = vec![];
|
||||||
|
|
||||||
|
@ -117,7 +123,7 @@ impl CompressedCRDTOperations {
|
||||||
record_id: record_id.clone(),
|
record_id: record_id.clone(),
|
||||||
timestamp: op.timestamp,
|
timestamp: op.timestamp,
|
||||||
data: op.data,
|
data: op.data,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{collections::BTreeMap, fmt::Debug};
|
use std::{collections::BTreeMap, fmt};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use specta::Type;
|
use specta::Type;
|
||||||
|
@ -11,8 +11,8 @@ pub enum OperationKind<'a> {
|
||||||
Delete,
|
Delete,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for OperationKind<'_> {
|
impl fmt::Display for OperationKind<'_> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
OperationKind::Create => write!(f, "c"),
|
OperationKind::Create => write!(f, "c"),
|
||||||
OperationKind::Update(field) => write!(f, "u:{field}"),
|
OperationKind::Update(field) => write!(f, "u:{field}"),
|
||||||
|
@ -36,11 +36,13 @@ pub enum CRDTOperationData {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CRDTOperationData {
|
impl CRDTOperationData {
|
||||||
|
#[must_use]
|
||||||
pub fn create() -> Self {
|
pub fn create() -> Self {
|
||||||
Self::Create(Default::default())
|
Self::Create(BTreeMap::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_kind(&self) -> OperationKind {
|
#[must_use]
|
||||||
|
pub fn as_kind(&self) -> OperationKind<'_> {
|
||||||
match self {
|
match self {
|
||||||
Self::Create(_) => OperationKind::Create,
|
Self::Create(_) => OperationKind::Create,
|
||||||
Self::Update { field, .. } => OperationKind::Update(field),
|
Self::Update { field, .. } => OperationKind::Update(field),
|
||||||
|
@ -62,17 +64,17 @@ pub struct CRDTOperation {
|
||||||
|
|
||||||
impl CRDTOperation {
|
impl CRDTOperation {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn kind(&self) -> OperationKind {
|
pub fn kind(&self) -> OperationKind<'_> {
|
||||||
self.data.as_kind()
|
self.data.as_kind()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for CRDTOperation {
|
impl fmt::Debug for CRDTOperation {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("CRDTOperation")
|
f.debug_struct("CRDTOperation")
|
||||||
.field("data", &self.data)
|
.field("data", &self.data)
|
||||||
.field("model", &self.model)
|
.field("model", &self.model)
|
||||||
.field("record_id", &self.record_id.to_string())
|
.field("record_id", &self.record_id.to_string())
|
||||||
.finish()
|
.finish_non_exhaustive()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,32 @@
|
||||||
|
#![warn(
|
||||||
|
clippy::all,
|
||||||
|
clippy::pedantic,
|
||||||
|
clippy::correctness,
|
||||||
|
clippy::perf,
|
||||||
|
clippy::style,
|
||||||
|
clippy::suspicious,
|
||||||
|
clippy::complexity,
|
||||||
|
clippy::nursery,
|
||||||
|
clippy::unwrap_used,
|
||||||
|
unused_qualifications,
|
||||||
|
rust_2018_idioms,
|
||||||
|
trivial_casts,
|
||||||
|
trivial_numeric_casts,
|
||||||
|
unused_allocation,
|
||||||
|
clippy::unnecessary_cast,
|
||||||
|
clippy::cast_lossless,
|
||||||
|
clippy::cast_possible_truncation,
|
||||||
|
clippy::cast_possible_wrap,
|
||||||
|
clippy::cast_precision_loss,
|
||||||
|
clippy::cast_sign_loss,
|
||||||
|
clippy::dbg_macro,
|
||||||
|
clippy::deprecated_cfg_attr,
|
||||||
|
clippy::separated_literal_suffix,
|
||||||
|
deprecated
|
||||||
|
)]
|
||||||
|
#![forbid(deprecated_in_future)]
|
||||||
|
#![allow(clippy::missing_errors_doc, clippy::module_name_repetitions)]
|
||||||
|
|
||||||
mod compressed;
|
mod compressed;
|
||||||
mod crdt;
|
mod crdt;
|
||||||
mod factory;
|
mod factory;
|
||||||
|
|
Loading…
Reference in a new issue