mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-06-30 12:33:31 +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.
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
|
|
|
@ -10,14 +10,21 @@
|
|||
clippy::unwrap_used,
|
||||
unused_qualifications,
|
||||
rust_2018_idioms,
|
||||
clippy::expect_used,
|
||||
trivial_casts,
|
||||
trivial_numeric_casts,
|
||||
unused_allocation,
|
||||
clippy::as_conversions,
|
||||
clippy::dbg_macro
|
||||
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(unsafe_code)]
|
||||
#![forbid(deprecated_in_future)]
|
||||
#![allow(clippy::missing_errors_doc, clippy::module_name_repetitions)]
|
||||
|
||||
use std::{fs, path::Path};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::mem;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uhlc::NTP64;
|
||||
use uuid::Uuid;
|
||||
|
@ -6,11 +8,12 @@ use crate::{CRDTOperation, CRDTOperationData};
|
|||
|
||||
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)]
|
||||
pub struct CompressedCRDTOperations(pub Vec<(Uuid, Vec<(u16, CompressedCRDTOperationsForModel)>)>);
|
||||
|
||||
impl CompressedCRDTOperations {
|
||||
#[must_use]
|
||||
pub fn new(ops: Vec<CRDTOperation>) -> Self {
|
||||
let mut compressed = vec![];
|
||||
|
||||
|
@ -32,34 +35,34 @@ impl CompressedCRDTOperations {
|
|||
for op in ops_iter {
|
||||
if instance_id != op.instance {
|
||||
model.push((
|
||||
std::mem::replace(&mut record_id, op.record_id.clone()),
|
||||
std::mem::take(&mut record),
|
||||
mem::replace(&mut record_id, op.record_id.clone()),
|
||||
mem::take(&mut record),
|
||||
));
|
||||
instance.push((
|
||||
std::mem::replace(&mut model_str, op.model),
|
||||
std::mem::take(&mut model),
|
||||
mem::replace(&mut model_str, op.model),
|
||||
mem::take(&mut model),
|
||||
));
|
||||
compressed.push((
|
||||
std::mem::replace(&mut instance_id, op.instance),
|
||||
std::mem::take(&mut instance),
|
||||
mem::replace(&mut instance_id, op.instance),
|
||||
mem::take(&mut instance),
|
||||
));
|
||||
} else if model_str != op.model {
|
||||
model.push((
|
||||
std::mem::replace(&mut record_id, op.record_id.clone()),
|
||||
std::mem::take(&mut record),
|
||||
mem::replace(&mut record_id, op.record_id.clone()),
|
||||
mem::take(&mut record),
|
||||
));
|
||||
instance.push((
|
||||
std::mem::replace(&mut model_str, op.model),
|
||||
std::mem::take(&mut model),
|
||||
mem::replace(&mut model_str, op.model),
|
||||
mem::take(&mut model),
|
||||
));
|
||||
} else if record_id != op.record_id {
|
||||
model.push((
|
||||
std::mem::replace(&mut record_id, op.record_id.clone()),
|
||||
std::mem::take(&mut record),
|
||||
mem::replace(&mut record_id, op.record_id.clone()),
|
||||
mem::take(&mut record),
|
||||
));
|
||||
}
|
||||
|
||||
record.push(CompressedCRDTOperation::from(op))
|
||||
record.push(CompressedCRDTOperation::from(op));
|
||||
}
|
||||
|
||||
model.push((record_id, record));
|
||||
|
@ -69,6 +72,7 @@ impl CompressedCRDTOperations {
|
|||
Self(compressed)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn first(&self) -> Option<(Uuid, u16, &rmpv::Value, &CompressedCRDTOperation)> {
|
||||
self.0.first().and_then(|(instance, 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)> {
|
||||
self.0.last().and_then(|(instance, data)| {
|
||||
data.last().and_then(|(model, data)| {
|
||||
|
@ -104,6 +109,7 @@ impl CompressedCRDTOperations {
|
|||
self.len() == 0
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn into_ops(self) -> Vec<CRDTOperation> {
|
||||
let mut ops = vec![];
|
||||
|
||||
|
@ -117,7 +123,7 @@ impl CompressedCRDTOperations {
|
|||
record_id: record_id.clone(),
|
||||
timestamp: op.timestamp,
|
||||
data: op.data,
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::BTreeMap, fmt::Debug};
|
||||
use std::{collections::BTreeMap, fmt};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
|
@ -11,8 +11,8 @@ pub enum OperationKind<'a> {
|
|||
Delete,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for OperationKind<'_> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl fmt::Display for OperationKind<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
OperationKind::Create => write!(f, "c"),
|
||||
OperationKind::Update(field) => write!(f, "u:{field}"),
|
||||
|
@ -36,11 +36,13 @@ pub enum CRDTOperationData {
|
|||
}
|
||||
|
||||
impl CRDTOperationData {
|
||||
#[must_use]
|
||||
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 {
|
||||
Self::Create(_) => OperationKind::Create,
|
||||
Self::Update { field, .. } => OperationKind::Update(field),
|
||||
|
@ -62,17 +64,17 @@ pub struct CRDTOperation {
|
|||
|
||||
impl CRDTOperation {
|
||||
#[must_use]
|
||||
pub fn kind(&self) -> OperationKind {
|
||||
pub fn kind(&self) -> OperationKind<'_> {
|
||||
self.data.as_kind()
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for CRDTOperation {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl fmt::Debug for CRDTOperation {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("CRDTOperation")
|
||||
.field("data", &self.data)
|
||||
.field("model", &self.model)
|
||||
.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 crdt;
|
||||
mod factory;
|
||||
|
|
Loading…
Reference in a new issue