Derive `From` on id types

This commit is contained in:
Mikolaj Wielgus 2026-05-23 19:38:01 +02:00
parent c525af7fca
commit 1b9673e3e7
8 changed files with 19 additions and 17 deletions

View File

@ -2,13 +2,13 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use derive_more::Constructor;
use derive_more::{Constructor, From};
use serde::{Deserialize, Serialize};
use crate::primitives::{JointId, PolygonId, SegmentId, ViaId};
#[derive(
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
Clone, Constructor, Copy, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct ComponentId(usize);

View File

@ -2,11 +2,11 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use derive_more::Constructor;
use derive_more::{Constructor, From};
use serde::{Deserialize, Serialize};
#[derive(
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
Clone, Constructor, Copy, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct NetId(usize);

View File

@ -2,13 +2,13 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use derive_more::Constructor;
use derive_more::{Constructor, From};
use serde::{Deserialize, Serialize};
use crate::primitives::{JointId, PolygonId, SegmentId, ViaId};
#[derive(
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
Clone, Constructor, Copy, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct PinId(usize);

View File

@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use derive_more::Constructor;
use derive_more::{Constructor, From};
use rstar::{AABB, primitives::Rectangle};
use serde::{Deserialize, Serialize};
@ -12,7 +12,7 @@ use crate::math::Vector2;
use super::{SegmentId, ViaId};
#[derive(
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
Clone, Constructor, Copy, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct JointId(usize);

View File

@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use derive_more::Constructor;
use derive_more::{Constructor, From};
use rstar::{AABB, Envelope, primitives::Rectangle};
use serde::{Deserialize, Serialize};
@ -10,7 +10,7 @@ use crate::compounds::{ComponentId, NetId, PinId};
use crate::math::Vector2;
#[derive(
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
Clone, Constructor, Copy, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct PolygonId(usize);

View File

@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use derive_more::Constructor;
use derive_more::{Constructor, From};
use rstar::primitives::Rectangle;
use serde::{Deserialize, Serialize};
@ -12,7 +12,7 @@ use crate::math::Vector2;
use super::JointId;
#[derive(
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
Clone, Constructor, Copy, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct SegmentId(usize);

View File

@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use derive_more::Constructor;
use derive_more::{Constructor, From};
use rstar::{AABB, primitives::Rectangle};
use serde::{Deserialize, Serialize};
@ -12,7 +12,7 @@ use crate::math::Vector2;
use super::JointId;
#[derive(
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
Clone, Constructor, Copy, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct ViaId(usize);

View File

@ -4,7 +4,7 @@
use dearcut::{RecordingTriangulator, VertexId};
use derive_getters::Getters;
use derive_more::Constructor;
use derive_more::{Constructor, From};
use serde::{Deserialize, Serialize};
use stable_vec::StableVec;
use undoredo::Recorder;
@ -16,7 +16,7 @@ use crate::{
};
#[derive(
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
Clone, Constructor, Copy, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct MultiObstacleId {
layer: usize,
@ -37,7 +37,9 @@ impl MultiObstacleId {
}
}
#[derive(Clone, Constructor, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
#[derive(
Clone, Constructor, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct MultiVertexId {
layer: usize,
indices: Vec<VertexId>,