diff --git a/app-proto/src/assembly.rs b/app-proto/src/assembly.rs index 92eaa62..8cf3bb3 100644 --- a/app-proto/src/assembly.rs +++ b/app-proto/src/assembly.rs @@ -44,13 +44,24 @@ impl Element { color: ElementColor, representation: DVector ) -> Element { + // take the next serial number, panicking if that was the last number we + // had left. the technique we use to panic on overflow is taken from + // _Rust Atomics and Locks_, by Mara Bos + // + // https://marabos.nl/atomics/atomics.html#example-handle-overflow + // + let serial = NEXT_ELEMENT_SERIAL.fetch_update( + Ordering::SeqCst, Ordering::SeqCst, + |serial| serial.checked_add(1) + ).expect("Out of serial numbers for elements"); + Element { id: id, label: label, color: color, representation: create_signal(representation), constraints: create_signal(BTreeSet::default()), - serial: NEXT_ELEMENT_SERIAL.fetch_add(1, Ordering::SeqCst), + serial: serial, column_index: 0 } }